اخبار نجومی

John Yembrick
Headquarters, Washington
202-358-0602
john.yembrick-1@nasa.gov
Paul Foerman
Stennis Space Center, Miss.
228-688-1880
paul.foerman@nasa.gov

Aug. 29, 2008

MEDIA ADVISORY : 08-164

Stennis Space Center to Close for Hurricane Gustav

BAY ST. LOUIS, Miss. -- NASA's John C. Stennis Space Center will close Friday, Aug. 29, at 4:30 p.m. CDT due to the approach of tropical storm Gustav, which is expected to strengthen into a hurricane. Normal operations at the facility are expected to resume when conditions permit.

Public tours to StenniSphere, the visitor center, from the Launch Pad at the I-10 Welcome Center in Hancock County, also will be suspended Friday. When conditions allow, the visitor center will return to its regular hours of operation, Wednesday -- Saturday, 10 a.m. to 3 p.m.

The public is reminded that Stennis Space Center is a government industrial complex. As such, the facility is not equipped to serve as a storm shelter.

For center status, Stennis employees and reporters should call 228-688-3777, or visit:

http://sscinfo.ssc.nasa.gov/eoc/bulletins/current.html
 

sunset

NGC3256

اخبار نجومی


Headquarters, Washington
202-358-0602
john.yembrick-1@nasa.gov
Paul Foerman
Stennis Space Center, Miss
228-688-1880
paul.foerman@nasa.gov

Aug. 29, 2008

MEDIA ADVISORY : M08-164 Stennis Space Center To Close For Hurricane Gustav BAY ST. LOUIS, Miss. -- NASA's John C. Stennis Space Center will close Friday, Aug. 29, at 4:30 p.m. CDT, due to the approach of tropical storm Gustav, which is expected to strengthen into a hurricane. Normal operations at the facility are expected to resume when conditions permi
Public tours to StenniSphere, the visitor center, from the Launch Pad at the I-10 Welcome Center in Hancock County, also will be suspended Friday. When conditions allow, the visitor center will return to its regular hours of operation, Wednesday -- Saturday, 10 a.m. to 3 p.m
The public is reminded that Stennis Space Center is a government industrial complex. As such, the facility is not equipped to serve as a storm shelter


For center status, Stennis employees and reporters should call 228-688-3777, or visit 

http://sscinfo.ssc.nasa.gov/eoc/bulletins/current.html


For information about Stennis Space Center, visi

http://www.nasa.gov/centers/stennis



 

اخبار نجومی

J.D. Harrington
Headquarters, Washington
202-358-5241
jharring@nasa.gov
Whitney Clavin
Jet Propulsion Laboratory, Pasadena, Calif.
818-354-4673
whitney.clavin@jpl.nasa.gov
Michael Walker
American Museum of Natural History, New York
212-769-5766
mwalker@amnh.org

Aug. 29, 2008

MEDIA ADVISORY: M08-161 NASA To Announce New Carl Sagan Fellowships WASHINGTON -- NASA will hold a news conference on Wednesday, Sept. 3, at 10:30 a.m. EDT, at the Rose Center for Earth and Space, Cullman Hall of the Universe, American Museum of Natural History in New York, to announce its new Carl Sagan Postdoctoral Fellowships in Exoplanet Exploration. The fellowships, named after the legendary astrophysicist, are designed to inspire the next generation of explorers seeking to learn more about planets, and possibly life, around other star Briefing participan:
- Jon Morse, director, Astrophysics Division, NASA Headquarters, Washington
- Ann Druyan, widow and collaborator of the late Carl Sagan, Ithaca, N.Y
- Charles Beichman, executive director, NASA's Exoplanet Science Institute, Pasadena, Calif
- Neil deGrasse Tyson, Frederick P. Rose director of the Hayden Planetarium, New York
Press attending the local event should use the Rose Center entrance on West 81st Street between Columbus Avenue and Central Park West and be in place by 10:25 a.m
Audio of the conference will be streamed live on NASA's Web site at

http://www.nasa.gov/newsaudio


 

کهکشان

NGC1275

اخبار نجومی

Sonja Alexander
Headquarters, Washington
202-358-1761
sonja.r.alexander@nasa.gov
Michelle Alvarez
AARP, Washington
202-390-0032
MAlvarez@aarp.org

Aug. 29, 2008

MEDIA ADVISORY: M08-162 NASA and AARP Celebrate 50 Years of Inspiration, Innovation and Discovery WASHINGTON -- NASA will join AARP in their Life at 50+ National Event and Expo as the two organizations each celebrate a half of century of remarkable achievements.
On Sept. 4, during the opening ceremony of the show at 9:30 a.m. EDT, NASA will present AARP with a photo montage honoring the organization's 50 years of service to the senior community. The montage will include items flown earlier this year on space shuttle Discovery
AARP will present NASA with an oversized AARP membership card to mark the agency turning 50. The event will be held at the Washington Convention Center, Washington. Former astronauts Michael Coats, director of NASA's Johnson Space Center in Houston, and Carl Walz, director of advanced capabilities in the Exploration Systems Mission Directorate at NASA Headquarters in Washington, will represent NASA during the event
In addition to the opening ceremony presentation, NASA will have a substantial presence at the Expo to showcase some of the Agency's various innovations and space hardware. Some of the highlighted exhibits include a "NASA City and Home" Wii interactive display, the Roll-Over Mars Rover and interactive Constellation Program exhibits

Media wanting to attend the opening ceremony and conference must register with AARP on the Web at

http://www.aarp.org/party


For information about NASA's 50th at the AARP National Event and Expo on the Web, visit

http://www.nasa.gov/50th/AARP



 

اخبار نجومی

John Yembrick
Headquarters, Washington
202-358-0602
john.yembrick-1@nasa.gov
Candrea Thomas
Kennedy Space Center, Fla.
321-867-2468
candrea.k.thomas@nasa.gov

Aug. 28, 2008

MEDIA ADVISORY: M08-160 NASA Updates Shuttle Atlantis' Move To Launch Pad Tuesday

CAPE CANAVERAL, Fla. -- Space shuttle Atlantis is scheduled to roll out to Launch Pad 39A at NASA's Kennedy Space Center at 12:01 a.m. EDT on Tuesday, Sept. 2. Atlantis is targeted to lift off Oct. 8 on an 11-day mission to service the Hubble Space Telescope. This new rollout date accommodates additional work on Atlantis. NASA Television will provide live video of Atlantis at the launch pad beginning at 6:30 a.m. on Sept. 2. Video highlights of the rollout will air on NASA TV's Video File segments. Media are invited to a photo opportunity of the shuttle at the pad and interview availability with Atlantis' Flow Director Angie Brewer at 8 a.m. Tuesday. Dates and times of this event are subject to change. Updates are available by calling 321-867-2525. Media must arrive at Kennedy's news center by 6 a.m. for transportation to the viewing area. Media accreditation for this event is closed. Foreign media with credentials must arrive at the Pass and I-D Building on State Road 3 by 6 a.m. for transportation to the news center.
Atlantis will be commanded by Scott Altman. Gregory C. Johnson will be pilot. Mission Specialists will be John Grunsfeld, Mike Massimino, Megan McArthur, Andrew Feustel and Michael Good.

For NASA TV downlink information, schedules and links to streaming video, visit:

http://www.nasa.gov/ntv


For more information about the STS-125 mission and crew, visit:

http://www.nasa.gov/shuttle

 

 

اخبار نجومی

Dwayne Brown
Headquarters, Washington
202-358-1726
dwayne.c.brown@nasa.gov
Guy Webster
Jet Propulsion Laboratory, Pasadena, Calif.
818-354-6278
guy.webster@jpl.nasa.gov

Aug. 26, 2008

RELEASE: 08-216 NASA's Mars Rover Opportunity Climbing Out of Victoria Crater. PASADENA, Calif. -- NASA's Mars Exploration rover Opportunity is heading back out to the Red Planet's surrounding plains nearly a year after descending into a large Martian crater to examine exposed ancient rock layers."We've done everything we entered Victoria Crater to do and more," said Bruce Banerdt, of NASA's Jet Propulsion Laboratory in Pasadena, Calif. Banerdt is project scientist for Opportunity and its rover twin, Spirit.
Having completed its job in the crater, Opportunity is now preparing to inspect loose cobbles on the plains. Some of these rocks, approximately fist-size and larger, were thrown long distances when objects hitting Mars blasted craters deeper than Victoria into the Red Planet. Opportunity has driven past scores of cobbles but examined only a few. "Our experience tells us there's lots of diversity among the cobbles," said Scott McLennan of the State University of New York, Stony Brook. McLennan is a long-term planning leader for the rover science team. "We want to get a better characterization of them. A statistical sampling from examining more of them will be important for understanding the geology of the area." Opportunity entered Victoria Crater on Sept. 11, 2007, after a year of scouting from the rim. Once a drivable inner slope was identified, the rover used contact instruments on its robotic arm to inspect the composition and textures of accessible layers. The rover then drove close to the base of a cliff called "Cape Verde," part of the crater rim, to capture detailed images of a stack of layers 20 feet tall. The information Opportunity has returned about the layers in Victoria suggest the sediments were deposited by wind and then altered by groundwater. "The patterns broadly resemble what we saw at the smaller craters Opportunity explored earlier," McLennan said. "By looking deeper into the layering, we are looking farther back in time." The crater stretches approximately a half mile in diameter and is deeper than any other seen by Opportunity. Engineers are programming Opportunity to climb out of the crater at the same place it entered. A spike in electric current drawn by the rover's left front wheel last month quickly settled discussions about whether to keep trying to edge even closer to the base of Cape Verde on a steep slope. The spike resembled one seen on Spirit when that rover lost the use of its right front wheel in 2006. Opportunity's six wheels are all still working after 10 times more use than they were designed to perform, but the team took the spike in current as a reminder that one could quit. "If Opportunity were driving with only five wheels, like Spirit, it probably would never get out of Victoria Crater," said JPL's Bill Nelson, a rover mission manager. "We also know from experience with Spirit that if Opportunity were to lose the use of a wheel after it is out on the level ground, mobility should not be a problem." Opportunity now drives with its robotic arm out of the stowed position. A shoulder motor has degraded over the years to the point where the rover team chose not to risk having it stop working while the arm is stowed on a hook. If the motor were to stop working with the arm unstowed, the arm would remain usable. Spirit has resumed observations after surviving the harshest weeks of southern Martian winter. The rover won't move from its winter haven until the amount of solar energy available to it increases a few months from now. The rover has completed half of a full-circle color panorama from its sun-facing location on the north edge of a low plateau called "Home Plate." "Both rovers show signs of aging, but they are both still capable of exciting exploration and scientific discovery," said JPL's John Callas, project manager for Spirit and Opportunity. The team's plan for future months is to drive Spirit south of Home Plate to an area where the rover last year found some bright, silica-rich soil. This could be possible evidence of effects of hot water. For images and information about NASA's Opportunity and Spirit Mars rovers, visit:
http://www.nasa.gov/rovers

 

اخبار نجومی

Sonja Alexander
Headquarters, Washington
202-358-1761
sonja.r.alexander@nasa.gov
Shannon Rush
Challenger Center for Space Science Education, Alexandria, Va.
888-683-9740
srush@challenger.org

Aug. 28, 2008

RELEASE: 08-217 .NASA and Challenger Center Combining Efforts for Students

WASHINGTON -- NASA and the Challenger Center for Space Science Education, Alexandria, Va., announced Thursday a cooperative Space Act Agreement to work together to encourage students to focus more on science, technology, engineering and mathematic studies and programs.
Through hands-on interactive educational activities, NASA and the Challenger Center will engage students, their teachers, their families, and the general public to help increase overall science and technology literacy.
Dr. June Scobee Rodgers, Challenger Center Founding Chairman said, "We are overjoyed with the signing of this agreement with NASA. When Challenger was lost, the families came together to look for a fitting legacy to honor those we lost - and to carry on with their mission.”
This agreement with NASA will benefit the ongoing mission of the Challenger Center as well as allow the center to work with America's space program.
The Challenger Center for Space Science Education was founded in 1986. Today the network of 50 Challenger Learning Centers across the U.S. trains more than 25,000 teachers annually to incorporate project- based learning and use the theme of space exploration to engage students in critical thinking, decision-making, communication, and teamwork. Over the past 22 years more than 8 million students have participated in Challenger Center programs.

For more information about NASA and agency programs, visit:

http://www.nasa.gov

For more information about the Challenger Center for Space Science Education, visit:

http://www.challenger.org

اخبار نجومی

MEDIA ADVISORY: M08-157 Space Station Provides Boost to High School Students in California

HOUSTON -- Students from Buchanan High School in Clovis, Calif., who are taking part in a 48 hour space station simulation, will get an extra boost when they receive a call from the real International Space Station. Students at the school will participate in a live in-flight education downlink with the International Space Station on Monday, Aug. 25, from 11:35 a.m. to 11:55 a.m. CDT. The live question-and-answer session will feature Expedition 17 astronaut Greg Chamitoff.
The students are participating in the Columbia Project, a simulated space station experience that exposes them to the challenging endeavor of human space exploration. The program, currently in its third year, is coordinated by a district educator who is a member of NASA's Network of Educator Astronaut Teachers Project which helps incorporate NASA education resources into school curriculum.
To prepare for the downlink, Columbia Project participants engaged in creating mock-ups of the space station and mission control, rocket fabrication, astronaut selection and training, and mission control and station operations.
NASA's education downlinks support the agency's efforts to encourage students to study and pursue careers in science, technology, engineering and math, or STEM. These events, facilitated by NASA's Teaching from Space Office use the unique experience of human space flight to promote and enhance STEM education.

Directors: Sonja Alexander
Headquarters, Washington
202-358-1761
sonja.r.alexander@nasa.gov
Jenna Mills
Johnson Space Center, Houston
281-244-0185
jenna.c.mills@nasa.gov


The downlink will air live on NASA Television and be streamed on the Web at:
http://www.nasa.gov/ntv


For information about NASA's education programs, visit:
http://www.nasa.gov/education

 

اخبار نجومی

RELEASE: 08-212 NASA Kennedy to Reopen for Normal Operations Friday

CAPE CANAVERAL, Fla. -- Managers at NASA's Kennedy Space Center, Fla., plan to reopen the center for normal operations Friday morning for workers' first shift. A slow-moving Tropical Storm Fay has kept Kennedy closed since Tuesday. The Kennedy Space Center Visitor Complex also will reopen Friday.
The center was set to open Thursday morning for limited operations, but Fay stalled off the coast from Kennedy overnight and continued to bring heavy rain and tropical storm force wind to the area through mid-day.
Personnel are reminded to exercise caution when entering their work areas and report any unsafe conditions or damage to their immediate supervisor.
Based on initial assessments, there is no damage to space flight hardware, such as the space shuttles and Hubble Space Telescope equipment. Some facilities did sustain minor damage. Most reports are of water intrusion that will require mopping up.
A group of emergency personnel, known as a "ride-out crew," has been on-site since Tuesday and will remain on-duty until Friday morning to provide real-time assessments.
All Kennedy workers should check with the center's hurricane information phone line for the latest status at 321-861-7900 or 1-866-572-4877 before reporting to work Friday.

Directors: John Yembrick
Headquarters, Washington
202-358-0602
john.yembrick@nasa.gov
Allard Beutel
Kennedy Space Center, Fla.
321-867-2468
allard.beutel@nasa.gov

Updates also are available online at:
http://www.nasa.gov/kennedy

And

http://www.nasa.gov/eoc

اخبار نجومی




CONTRACT RELEASE: C08-055 NASA Ames Awards Contract for Engineering Support

MOFFETT FIELD, Calif. -- NASA's Ames Research Center at Moffett Field, Calif., Thursday awarded a cost plus fixed fee indefinite delivery, indefinite quantity task order contract valued at $42 million to ASRC Research and Technology Solutions (ARTS), of Greenbelt, Md. ARTS is a Alaskan Native Corporation under the Small Business Administration 8 (a) Business Development Program that will provide engineering, design and fabrication services for the center.
ARTS will provide services including project management, systems engineering, hardware and software design and development, mechanical and electronic fabrication services, integration and testing, technical writing, configuration management and other functions at Ames.
The five-year contract consists of a one-year base period, followed by four one-year options.

Directors: Ashley Edwards
Headquarters, Washington
202-358-1756
ashley.edwards-1@nasa.gov
Michael Mewhinney
Ames Research Center, Moffett Field, Calif.
650-604-3937/207-1323
michael.s.mewhinney@nasa.gov

 


For more information about NASA's Ames Research Center, visit
http://www.arc.nasa.gov

 

اخبار نجومی

MEDIA ADVISORY: M08-215 NASA Invites Media to Experience Lunar Exploration close up

HOUSTON -- Reporters will have a unique chance to experience lunar life, including driving across and touching a simulated moonscape, on Monday, Sept. 8, at NASA's Johnson Space Center in Houston.
The Lunar Exploration Workshop will be held from 1:30 p.m. to 5 p.m. CDT, immediately following morning briefings that preview NASA's next space shuttle mission. The STS-125 flight of Atlantis will be the final visit by astronauts to the Hubble Space Telescope.
During Monday's tour, reporters will visit NASA's lunar yard to view NASA's prototype lunar truck as it travels across the mock surface of the moon. They will be able to climb into a concept lunar lander in the Altair development lab and examine moon rocks brought back to Earth by Apollo astronauts.
The sessions will include interviews with experts and managers from NASA's Constellation Program. The Constellation Program is building America's next spacecraft and planning a return of humans to live and work on the moon.
Reporters must contact the Johnson Space Center newsroom at 281-483-5111 by 5 p.m. Sept. 3, to register.
Directors: Stephanie Schierholz/Grey Hautaluoma
Headquarters, Washington
202-358-4997/0668
stephanie.schierholz@nasa.gov
grey.hautaluoma-1@nasa.gov

Josh Byerly/Lynnette Madison
Johnson Space Center, Houston
281-483-5111
josh.byerly@nasa.gov
lynnette.b.bmadison@nasa.gov

 

For more information about NASA's Constellation Program, visit:
http://www.nasa.gov/constellation



 

اخبار نجومی

MEDIA ADVISORY: M08-159 NASA's Space Shuttle Atlantis to Move to Launch Pad Saturday

CAPE CANAVERAL, Fla. - Space shuttle Atlantis is scheduled to roll out to Launch Pad 39A at NASA's Kennedy Space Center on Saturday, Aug. 30. Atlantis is targeted to lift off Oct. 8 to repair the Hubble Space Telescope.
The first motion of the shuttle out of Kennedy's Vehicle Assembly Building is scheduled for 12:01 a.m. EDT. The fully assembled space shuttle, consisting of the orbiter, external tank and twin solid rocket boosters, was mounted on a mobile launcher platform and will be delivered to the pad atop a crawler-transporter. The crawler will travel slower than 1 mph during the 3.4-mile journey. The process is expected to take approximately six hours.
Repairs to Launch Pad 39A's flame trench wall were completed Aug. 5 after crews installed a steel grid structure and covered it in a heat-resistant material. The pad's north flame trench was damaged when bricks tore away from the wall during the May 31 launch of space shuttle Discovery. NASA Television will provide live coverage of Atlantis' move to the launch pad beginning at 6:30 a.m. Video highlights of the rollout will air on NASA TV Video File.
Media are invited to a photo opportunity of roll out and interview availability with Atlantis Flow Director Angie Brewer at 8 a.m. Saturday. Dates and times of this event are subject to change. Updates are available by calling 321-867-2525. Reporters must arrive at Kennedy's news center by 6 a.m. Saturday for transportation to the viewing area. Foreign news media accreditation for this event has closed. Foreign media with credentials must arrive at the Pass and I-D Building on State Road 3 by 6 a.m. for transportation to the news center. U.S. media without permanent Kennedy Space Center credentials must apply for accreditation online by 4 p.m. Wednesday, Aug. 27, at: https://media.ksc.nasa.gov Badges must be picked up by 4 p.m. Friday, Aug. 29, at the new Kennedy Badging Office on State Road 405, west of Gate 3 (just past the Kennedy Visitor’s Complex). During its 11-day mission that includes five spacewalks, the STS-125's crew of seven astronauts will install two new instruments in Hubble, as well as replace the Fine Guidance Sensor. The result will be six working, complementary science instruments with capabilities beyond those now available, and an extended operational lifespan of the telescope through at least 2013.
Atlantis will be commanded by Scott Altman. Gregory C. Johnson will be pilot. Mission Specialists will be John Grunsfeld, Mike Massimino, Megan McArthur, Andrew Feustel and Michael Good.
Directors: John Yembrick
Headquarters, Washington
202-358-0602
john.yembrick-1@nasa.gov
Candrea Thomas
Kennedy Space Center, Fla.
321-867-2468
candrea.k.thomas@nasa.gov

For NASA TV downlink information, schedules and links to streaming video, visit:
http://www.nasa.gov/ntv


For more information about the STS-125 mission and crew, visit:
http://www.nasa.gov/shuttle

 

 

اخبار نجومی

J.D. Harrington
Headquarters, Washington
202-358-5241
j.d.harrington@nasa.gov
David Harris
Stanford Linear Accelerator Center, Menlo Park, Calif.
650-926-8580
david.harris@slac.stanford.edu
Lynn Cominsky
Sonoma State University, Rohnert Park, Calif.
707-664-2655
lynnc@universe.sonoma.edu

Aug. 26, 2008

RELEASE: 08-214 NASA Renames Observatory For Fermi, Reveals Entire Gamma-Ray Sky

WASHINGTON -- NASA's newest observatory, the Gamma-Ray Large Area Space Telescope, or GLAST, has begun its mission of exploring the universe in high-energy gamma rays. The spacecraft and its revolutionary instruments passed their orbital checkout with flying colors.
NASA announced today that GLAST has been renamed the Fermi Gamma-ray Space Telescope. The new name honors Prof. Enrico Fermi (1901 - 1954), a pioneer in high-energy physics.
"Enrico Fermi was the first person to suggest how cosmic particles could be accelerated to high speeds," said Paul Hertz, chief scientist for NASA's Science Mission Directorate at NASA Headquarters in Washington. "His theory provides the foundation for understanding the new phenomena his namesake telescope will discover."
Scientists expect Fermi will discover many new pulsars in our own galaxy, reveal powerful processes near supermassive black holes at the cores of thousands of active galaxies and enable a search for signs of new physical laws.
For two months following the spacecraft's June 11 launch, scientists tested and calibrated its two instruments, the Large Area Telescope (LAT) and the GLAST Burst Monitor (GBM).
The LAT team today unveiled an all-sky image showing the glowing gas of the Milky Way, blinking pulsars, and a flaring galaxy billions of light-years away. The map combines 95 hours of the instrument's "first light" observations. A similar image, produced by NASA's now-defunct Compton Gamma-ray Observatory, took years of observations to produce.
The image shows gas and dust in the plane of the Milky Way glowing in gamma rays due to collisions with accelerated nuclei called cosmic rays. The famous Crab Nebula and Vela pulsars also shine brightly at these wavelengths. These fast-spinning neutron stars, which form when massive stars die, were originally discovered by their radio emissions. The image's third pulsar, named Gemming and located in Gemini, is not a radio source. It was discovered by an earlier gamma-ray satellite. Fermi is expected to discover many more radio-quiet pulsars, providing key information about how these exotic objects work.
A fourth bright spot in the LAT image lies some 7.1 billion light-years away, far beyond our galaxy. This is 3C 454.3 in Pegasus, a type of active galaxy called a blazer. It's now undergoing a flaring episode that makes it especially bright.
The LAT scans the entire sky every three hours when operating in survey mode, which will occupy most of the telescope's observing time during the first year of operations. These fast snapshots will let scientists monitor rapidly changing sources. The instrument detects photons with energies ranging from 20 million electron volts to over 300 billion electron volts. The high end of this range, which corresponds to energies more than 5 million times greater than dental X-rays, is little explored. The spacecraft's secondary instrument, the GBM, spotted 31 gamma-ray bursts in its first month of operations. These high-energy blasts occur when massive stars die or when orbiting neutron stars spiral together and merge.
The GBM is sensitive to less energetic gamma rays than the LAT. Bursts seen by both instruments will provide an unprecedented look across a broad gamma-ray spectrum, enabling scientists to peer into the processes powering these events.
NASA's Fermi Gamma-ray Space Telescope is an astrophysics and particle physics partnership, developed in collaboration with the U.S. Department of Energy, along with important contributions from academic institutions and partners in France, Germany, Italy, Japan, Sweden and the U.S. For more information, images and animations on the Web, visit:
http://www.nasa.gov/glast

 

اخبار نجومی

RELEASE: 08-210 NASA Kennedy Space Center Partly Reopens

CAPE CANAVERAL, Fla. -- NASA's Kennedy Space Center, Fla., will reopen Thursday at 10 a.m. EDT for "mission essential" personnel. Kennedy has been closed since Tuesday because of Tropical Storm Fay, which is continuing to bring heavy rain and wind to the region.
Individual center supervisors will define which workers are considered "mission essential." These will include employees who are needed to ensure center infrastructure is safe and working, and personnel who process spaceflight hardware, such as space shuttles and Hubble Space Telescope equipment. A liberal leave policy for employees will be in effect Thursday. Kennedy Space Center Visitor Complex will remain closed Thursday, but reopen on Friday.
Plans call for the center to open to all employees and return to full operation Friday.
Based on initial assessments, there are no injuries, damage to flight hardware or flooding associated with Fay at the center. Only minor damage has been seen on a few facilities, including the Vehicle Assembly Building, which lost one exterior panel from its east side.
About 200 emergency personnel, known as a "ride-out crew," will remain on-site overnight into Thursday morning to provide real-time storm assessments.
Kennedy workers should check with the center's hurricane information phone line for the latest status: 321-861-7900 or 1-866-572-4877. Employees should check with their supervisors if they have not been notified about their Thursday work status.

Directors: John Yembrick
Headquarters, Washington
202-358-0602
john.yembrick@nasa.gov
Allard Beutel
Kennedy Space Center, Fla.
321-867-2468
allard.beutel@nasa.gov


Storm updates also are available online at the agency's emergency operation center Web site:

http://www.nasa.gov/eoc

 

اخبار نجومی

RELEASE: 08-211 Fay Delays NASA Kennedy Space Center Partial Reopening

CAPE CANAVERAL, Fla. -- Managers at NASA's Kennedy Space Center, Fla., are delaying reopening the center for mission essential personnel Thursday morning because of slow-moving Tropical Storm Fay. Personnel should not report for work at 10 a.m. EDT as previously directed, but instead should check the center's status through the hurricane phone lines and emergency operations center Web site at noon.
Plans still call for the center to open to all employees and return to full operation Friday.
Fay stalled off the coast from Kennedy overnight. It continues to bring heavy rain and tropical storm force wind to the area.
Individual center supervisors have defined which workers are considered mission essential. These will include employees who are needed to ensure center infrastructure is safe and working, and personnel who process space flight hardware, such as space shuttles and Hubble Space Telescope equipment.
Based on initial assessments, there are no injuries or damage to flight hardware associated with Fay at the center.
About 200 emergency personnel, known as a "ride-out crew," remain on-site Thursday to provide real-time storm assessments.
All Kennedy workers should check with the center's hurricane information phone line for the latest status at 321-861-7900 or 1-866-572-4877. Storm

      Directors: John Yembrick*
Headquarters, Washington
202-358-0602
john.yembrick@nasa.gov
Allard Beutel
Kennedy Space Center, Fla.
321-867-2468
allard.beutel@nasa.gov


Updates also are available online at the agency's emergency operation center Web site

http://www.nasa.gov/eoc



تصویر ویجر (2) از منظومه شمسی

آموزش زبان c قسمت 5:

The C programming language uses the "=" character for assignment. A statement of the form a=10; should be interpreted as take the numerical value 10 and store it in a memory location associated with the integer variable a. The "=" character should not be seen as an equality otherwise writing statements of the form:

a=a+10;

will get mathematicians blowing fuses! This statement should be interpreted as take the current value stored in a memory location associated with the integer variable a; add the numerical value 10 to it and then replace this value in the memory location associated with a.


Decimal Number Variables

As described above, an integer variable has no fractional part. Integer variables tend to be used for counting, whereas real numbers are used in arithmetic. C uses one of two keywords to declare a variable that is to be associated with a decimal number: float and double. They are each offer a different level of precision as outlined below.

float

A float, or floating point, number has about seven digits of precision and a range of about 1.E-36 to 1.E+36. A float takes four bytes to store.

double

A double, or double precision, number has about 13 digits of precision and a range of about 1.E-303 to 1.E+303. A double takes eight bytes to store.

For example:

float total;

double sum;

To assign a numerical value to our floating point and double precision variables we would use the following C statement:

total=0.0;

sum=12.50;


Character Variables

C only has a concept of numbers and characters. It very often comes as a surprise to some programmers who learnt a beginner's language such as BASIC that C has no understanding of strings but a string is only an array of characters and C does have a concept of arrays which we shall be meeting later in this course.

To declare a variable of type character we use the keyword char. - A single character stored in one byte.

For example:

char c;

To assign, or store, a character value in a char data type is easy - a character variable is just a symbol enclosed by single quotes. For example, if c is a char variable you can store the letter A in it using the following C statement:

c='A'

Notice that you can only store a single character in a char variable. Later we will be discussing using character strings, which has a very real potential for confusion because a string constant is written between double quotes. But for the moment remember that a char variable is 'A' and not "A".


Assignment Statement

Once you've declared a variable you can use it, but not until it has been declared - attempts to use a variable that has not been defined will cause a compiler error. Using a variable means storing something in it. You can store a value in a variable using:

name = value;

For example:

a=10;

stores the value 10 in the int variable a. What could be simpler? Not much, but it isn't actually very useful! Who wants to store a known value like 10 in a variable so you can use it later? It is 10, always was 10 and always will be 10. What makes variables useful is that you can use them to store the result of some arithmetic.

Consider four very simple mathematical operations: add, subtract, multiply and divide. Let us see how C would use these operations on two float variables a and b.

add

a+b

subtract

a-b

multiply

a*b

divide

a/b

Note that we have used the following characters from C's character set:

+     for add

-     for subtract

*     for multiply

/     for divide

BE CAREFUL WITH ARITHMETIC!!! What is the answer to this simple calculation?

a=10/3

The answer depends upon how a was declared. If it was declared as type int the answer will be 3; if a is of type float then the answer will be 3.333. It is left as an exercise to the reader to find out the answer for a of type char.

Two points to note from the above calculation:

  1. C ignores fractions when doing integer division!
  2. when doing float calculations integers will be converted into float. We will see later how C handles type conversions.

Arithmetic Ordering

Whilst we are dealing with arithmetic we want to remind you about something that everyone learns at junior school but then we forget it. Consider the following calculation:

a=10.0 + 2.0 * 5.0 - 6.0 / 2.0

What is the answer? If you think its 27 go to the bottom of the class! Perhaps you got that answer by following each instruction as if it was being typed into a calculator. A computer doesn't work like that and it has its own set of rules when performing an arithmetic calculation. All mathematical operations form a hierarchy which is shown here. In the above calculation the multiplication and division parts will be evaluated first and then the addition and subtraction parts. This gives an answer of 17.

Note: To avoid confusion use brackets. The following are two different calculations:

a=10.0 + (2.0 * 5.0) - (6.0 / 2.0)
a=(10.0 + 2.0) * (5.0 - 6.0) / 2.0

You can freely mix int, float and double variables in expressions. In nearly all cases the lower precision values are converted to the highest precision values used in the expression. For example, the expression f*i, where f is a float and i is an int, is evaluated by converting the int to a float and then multiplying. The final result is, of course, a float but this may be assigned to another data type and the conversion will be made automatically. If you assign to a lower precision type then the value is truncated and not rounded. In other words, in nearly all cases you can ignore the problems of converting between types.

This is very reasonable but more surprising is the fact that the data type char can also be freely mixed with ints, floats and doubles. This will shock any programmer who has used another language, as it's another example of C getting us closer than is customary to the way the machine works. A character is represented as an ASCII or some other code in the range O to 255, and if you want you can use this integer code value in arithmetic. Another way of thinking about this is that a char variable is just a single-byte integer variable that can hold a number in the range O to 255, which can optionally be interpreted as a character. Notice, however, that C gives you access to memory in the smallest chunks your machine works with, i.e. one byte at a time, with no overheads.


Something To Declare

Before you can use a variable you have to declare it. As we have seen above, to do this you state its type and then give its name. For example, int i; declares

آموزش زبان ز قسمت 6:

an integer variable. You can declare any number of variables of the same type with a single statement. For example:

int a, b, c;

declares three integers: a, b and c. You have to declare all the variables that you want to use at the start of the program. Later you will discover that exactly where you declare a variable makes a difference, but for now you should put variable declarations after the opening curly bracket of the main program.

Here is an example program that includes some of the concepts outlined above. It includes a slightly more advanced use of the printf function which will covered in detail in the next part of this course:

/*

/*

    Program#int.c

 

    Another simple program

    using int and printf

*/

 

#include

 

main()

{

    int a,b,average;

    a=10;

    b=6;

    average = ( a+b ) / 2 ;

    printf("Here ");

    printf("is ");

    printf("the ");

    printf("answer... ");

    printf("\n");

    printf("%d.",average);

}

[program]


More On Initialising Variables

You can assign an initial value to a variable when you declare it. For example:

int i=1;

sets the int variable to one as soon as it's created. This is just the same as:

int i;

i=l;

 

but the compiler may be able to speed up the operation if you initialise the variable as part of its declaration. Don't assume that an uninitialised variable has a sensible value stored in it. Some C compilers store 0 in newly created numeric variables but nothing in the C language compels them to do so.


Summary

Variable names:

  • should be lowercase for local variables
  • should be UPPERCASE for symbolic constants (to be discussed later)
  • only the first 31 characters of a variables name are significant
  • must begin with a letter or _ (under score) character

 


 

 

Input and Output Functions


Objectives

Having read this section you should have a clearer idea of one of C's:

  1. input functions, called scanf
  2. output functions, called printf

On The Run

Even with arithmetic you can't do very much other than write programs that are the equivalent of a pocket calculator. The real break through comes when you can read values into variables as the program runs. Notice the important words here: "as the program runs". You can already store values in variables using assignment. That is:

a=100;

stores 100 in the variable a each time you run the program, no matter what you do. Without some sort of input command every program would produce exactly the same result every time it was run. This would certainly make debugging easy! But in practice, of course, we need programs to do different jobs each time they are run. There are a number of different C input commands, the most useful of which is the scanf command. To read a single integer value into the variable called a you would use:

scanf("%d",&a);

For the moment don't worry about what the %d or the &a means - concentrate on the difference between this and:

a=100;

When the program reaches the scanf statement it pauses to give the user time to type something on the keyboard and continues only when users press , or , to signal that he, or she, has finished entering the value. Then the program continues with the new value stored in a. In this way, each time the program is run the user gets a chance to type in a different value to the variable and the program also gets the chance to produce a different result!

The final missing piece in the jigsaw is using the printf function, the one we have already used to print "Hello World", to print the value currently being stored in a variable. To display the value stored in the variable a you would use:

printf("The value stored in a is %d",a);

The %d, both in the case of scanf and printf, simply lets the compiler know that the value being read in, or printed out, is a decimal integer - that is, a few digits but no decimal point.

Note: the scanf function does not prompt for an input. You should get in the habit of always using a printf function, informing the user of the program what they should type, before a scanf function.


Input and Output Functions in More Detail

One of the advantages of C is that essentially it is a small language. This means that you can write a complete description of the language in a few pages. It doesn't have many keywords or data types for that matter. What makes C so powerful is the way that these low-level facilities can be put together to make higher level facilities.

The only problem with this is that C programmers have a tendency to reinvent the wheel each time they want to go for a ride. It is also possible to write C programs in a variety of styles which depend on the particular tricks and devices that a programmer chooses to use. Even after writing C for a long time you will still find the occasionally construction which makes you think, "I never thought of that!" or, "what is that doing?"

One attempt to make C a more uniform language is the provision of standard libraries of functions that perform common tasks. We say standard but until the ANSI committee actually produced a standard there was, and still is, some variation in what the standard libraries contained and exactly how the functions worked. Having said that we had better rush in quickly with the reassurance that in practice the situation isn't that bad and most of the functions that are used

آوزش زبان c قسمت 7:

frequently really are standard on all implementations. In particular the I/O functions vary very little.

It is now time to look at exactly how scanf and printf work and what they can do - you might be surprised at just how complex they really are!

The original C specification did not include commands for input and output. Instead the compiler writers were supposed to implement library functions to suit their machines. In practice all chose to implement printf and scanf and after a while C programmers started to think of them as if these functions were I/O keywords! It sometimes helps to remember that they are functions on a par with any other functions you may care to define. If you want to you can provide your own implementations of printf or scanf or any of the other standard functions - we'll discover how later.


printf

The printf (and scanf) functions do differ from the sort of functions that you will created for yourself in that they can take a variable number of parameters. In the case of printf the first parameter is always a string (c.f. "Hello World") but after that you can include as many parameters of any type that you want to. That is, the printf function is usually of the form:

printf(string,variable,variable,variable...)

where the ... means you can carry on writing a list of variables separated by commas as long as you want to. The string is all-important because it specifies the type of each variable in the list and how you want it printed. The string is usually called the control string or the format string. The way that this works is that printf scans the string from left to right and prints on the screen, or any suitable output device, any characters it encounters - except when it reaches a % character. The % character is a signal that what follows it is a specification for how the next variable in the list of variables should be printed. printf uses this information to convert and format the value that was passed to the function by the variable and then moves on to process the rest of the control string and anymore variables it might specify. For example:

printf("Hello World");

only has a control string and, as this contains no % characters it results in Hello World being displayed and doesn't need to display any variable values. The specifier %d means convert the next value to a signed decimal integer and so:

printf("Total = %d",total);

will print Total = and then the value passed by >total as a decimal integer.

If you are familiar other programming languages then you may feel happy about the printf function because something like:

printf("Total = %d",total);

looks like the sort of output command you might have used before. For example, in BASIC you would write:

PRINT "Total = ",total

but the C view of output is at a lower level than you might expect. The %d isn't just a format specifier, it is a conversion specifier. It indicates the data type of the variable to be printed and how that data type should be converted to the characters that appear on the screen. That is %d says that the next value to be printed is a signed integer value (i.e. a value that would be stored in a standard int variable) and this should be converted into a sequence of characters (i.e. digits) representing the value in decimal. If by some accident the variable that you are trying to display happens to be a float or a double then you will still see a value displayed - but it will not correspond to the actual value of the float or double.

The reason for this is twofold.

  1. The first difference is that an int uses two bytes to store its value, while a float uses four and a double uses eight. If you try to display a float or a double using %d then only the first two bytes of the value are actually used.
  2. The second problem is that even if there wasn't a size difference ints, floats and doubles use a different binary representation and %d expects the bit pattern to be a simple signed binary integer.

This is all a bit technical, but that's in the nature of C. You can ignore these details as long as you remember two important facts:

  1. The specifier following % indicates the type of variable to be displayed as well as the format in which that the value should be displayed;
  2. If you use a specifier with the wrong type of variable then you will see some strange things on the screen and the error often propagates to other items in the printf list.

If this seems complicated then I would agree but I should also point out that the benefit is being able to treat what is stored in a variable in a more flexible way than other languages allow. Other languages never let on to the programmer that what is in fact stored in a variable is a bit pattern, not the decimal value that appears to be stored there when you use a printf (or whatever) statement. Of course whether you view this as an advantage depends on what you are trying to do. It certainly brings you closer to the way the machine works.

You can also add an 'l' in front of a specifier to mean a long form of the variable type and h to indicate a short form (long and short will be covered later in this course). For example, %ld means a long integer variable (usually four bytes) and %hd means short int. Notice that there is no distinction between a four-byte float and an eight-byte double. The reason is that a float is automatically converted to a double precision value when passed to printf - so the two can be treated in the same way. (In pre-ANSI all floats were converted to double when passed to a function but this is no longer true.) The only real problem that this poses is how to print the value of a pointer? The answer is that you can use %x to see the address in hex or %o to see the address in octal. Notice that the value printed is the segment offset and not the absolute address - to understand what we am going on about you need to know something about the structure of your processor.


The % Format Specifiers

The % specifiers that you can use in ANSI C are:

      Usual variable type           Display

 

%c        char                     single character

%d (%i)   int                      signed integer

%e (%E)   float or double          exponential format

%f        float or double          signed decimal

%g (%G)   float or double          use %f or %e as required

%o        int                      unsigned octal value

%p        pointer                  address stored in pointer

%s        array of char            sequence of characters

%u        int                      unsigned decimal

%x (%X)   int                      unsigned hex value

 


Formatting Your Output

The type conversion specifier only does what you ask of it - it convert a given bit pattern into a sequence of characters that a human can read. If you want to format the characters then you need to know a little more about the printf function's control string.

Each specifier can be preceded by a modifier which determines how the value will be printed. The most general modifier is of the form:

flag width.precision

The flag can be any of:

flag          meaning

 

   -         left justify

   +         always display sign

   space     display space if there is no sign

   0         pad with leading zeros

   #         use alternate form of specifier

 

The width specifies the number of characters used in total to display the value and precision indicates the number of characters used after the decimal point.

For example, %10.3f will display the float using ten characters with three digits after the decimal point. Notice that the ten characters includes the decimal point, and a - sign if there is one. If the value needs more space than the width specifies then the additional space is used - width specifies the smallest space that will be used to display the value. (This is quiet reassuring, you won't be the first programmer whose program takes hours to run but the output results can't be viewed because the wrong format width has been specified!)

The specifier %-1Od will display an int left justified in a ten character space. The specifier %+5d will display an int using the next five character locations and will add a + or - sign to the value.

The only complexity is the use of the # modifier. What this does depends on which type of format it is used with:

 

%#o    adds a leading 0 to the octal value

%#x    adds a leading 0x to the hex value

 

آموزش زبان c قسمت 8:

%#f or

%#e    ensures decimal point is printed

%#g    displays trailing zeros

           

Strings will be discussed later but for now remember: if you print a string using the %s specifier then all of the characters stored in the array up to the first null will be printed. If you use a width specifier then the string will be right justified within the space. If you include a precision specifier then only that number of characters will be printed.

For example:

printf("%s,Hello")

will print Hello,

printf("%25s ,Hello")

will print 25 characters with Hello right justified and

printf("%25.3s,Hello")

will print Hello right justified in a group of 25 spaces.

Also notice that it is fine to pass a constant value to printf as in printf("%s,Hello").

Finally there are the control codes:

 

\b       backspace

\f       formfeed

\n       new line

\r       carriage return

\t       horizontal tab

\'       single quote

\0       null

 

If you include any of these in the control string then the corresponding ASCII control code is sent to the screen, or output device, which should produce the effect listed. In most cases you only need to remember \n for new line.


scanf

Now that we have mastered the intricacies of printf you should find scanf very easy. The scanf function works in much the same way as the printf. That is it has the general form:

scanf(control string,variable,variable,...)

In this case the control string specifies how strings of characters, usually typed on the keyboard, should be converted into values and stored in the listed variables. However there are a number of important differences as well as similarities between scanf and printf.

The most obvious is that scanf has to change the values stored in the parts of computers memory that is associated with parameters (variables).

To understand this fully you will have to wait until we have covered functions in more detail. But, just for now, bare with us when we say to do this the scanf function has to have the addresses of the variables rather than just their values. This means that simple variables have to be passed with a preceding >&. (Note for future reference: There is no need to do this for strings stored in arrays because the array name is already a pointer.)

The second difference is that the control string has some extra items to cope with the problems of reading data in. However, all of the conversion specifiers listed in connection with printf can be used with scanf.

The rule is that scanf processes the control string from left to right and each time it reaches a specifier it tries to interpret what has been typed as a value. If you input multiple values then these are assumed to be separated by white space - i.e. spaces, newline or tabs. This means you can type:

3 4 5

or

3

4

5

 

and it doesn't matter how many spaces are included between items. For example:

scanf("%d %d",&i,&j);

will read in two integer values into i and j. The integer values can be typed on the same line or on different lines as long as there is at least one white space character between them.

The only exception to this rule is the %c specifier which always reads in the next character typed no matter what it is. You can also use a width modifier in scanf. In this case its effect is to limit the number of characters accepted to the width.

For example:

scanf("%lOd",&i)

would use at most the first ten digits typed as the new value for i.

There is one main problem with scanf function which can make it unreliable in certain cases. The reason being is that scanf tends to ignore white spaces, i.e. the space character. If you require your input to contain spaces this can cause a problem. Therefore for string data input the function getstr() may well be more reliable as it records spaces in the input text and treats them as an ordinary characters.


Custom Libraries

If you think printf and scanf don't seem enough to do the sort of job that any modern programmer expects to do, you would be right. In the early days being able to print a line at a time was fine but today we expect to be able to print anywhere on the screen at any time.

The point is that as far as standard C goes simple I/O devices are stream-oriented - that is you send or get a stream of characters without any notion of being able to move the current position in the stream. If you want to move backwards and forwards through the data then you need to use a direct access file. In more simple terms, C doesn't have a Tab(X,Y) or Locate(X,Y) function or command which moves the cursor to the specified location! How are you ever going to write your latest block buster game, let alone build your sophisticated input screens?

Well you don't have to worry too much because although C may not define them as standard, all C implementations come with an extensive graphics/text function library that allows you to do all of this and more. Such a library isn't standard, however the principles are always the same. The Borland and Microsoft offerings are usually considered as the two facto standards.


Summing It Up

Now that we have arithmetic, a way of reading values in and a way of displaying them, it's possible to write a slightly more interesting program than "Hello World". Not much more interesting, it's true, but what do you expect with two instructions and some arithmetic?

Let's write a program that adds two numbers together and prints the result. (I told you it wasn't that much more interesting!) Of course, if you want to work out something else like Fahrenheit to centigrade, inches to centimetres or the size of your bank balance, then that's up to you - the principle is the same.

The program is a bit more complicated than you might expect, but only because of the need to let the user know what is happening:

 

#include

main()

 {

   int a,b,c;

   printf("\nThe first number is ");

   scanf("%d",&a);

   printf("The second number is ");

   scanf("%d",&b);

   c=a+b;

   printf("The answer is %d \n",c);

 }

 

[program]

The first instruction declares three integer variables: a, b and c. The first two printf statements simply display message on the screen asking the user for the values. The scanf functions then read in the values from the keyboard into a and b. These are added together and the result in c is displayed on the screen with a suitable message. Notice the way that you can include a message in the printf statement along with the value.

 

آموزش زبان c قسمت 9:

Type the program in, compile it and link it and the result should be your first interactive program. Try changing it so that it works out something a little more adventurous. Try changing the messages as well. All you have to remember is that you cannot store values or work out results greater than the range of an integer variable or with a fractional part.


 

 

Control Loops


Objectives

Having read this section you should have an idea about C's:

  1. Conditional, or Logical, Expressions as used in program control
  2. the do while loop
  3. the while loop
  4. the for loop

Go With The Flow

Our programs are getting a bit more sophisticated, but they still lack that essential something that makes a computer so necessary. Exactly what they lack is the most difficult part to describe to a beginner. There are only two great ideas in computing. The first is the variable and you've already met that. The second is flow of control.

When you write a list of instructions for someone to perform you usually expect them to follow the list from the top to the bottom, one at a time. This is the simple default flow of control through a program. The C programs we have written so far use this one-after-another default flow of control.

This is fine and simple, but it limits the running time of any program we can write. Why? Simply because there is a limit to the number of instructions you can write and it doesn't take long for a computer to read though and obey your list. So how is it that we have programs that run for hours on end if need be? The answer is statements that alter the one-after-another order of obeying instructions. Perhaps the most useful is the loop.

Suppose we ask you to display "Hello World!" five times on the screen. Easy! you'd say:

 

#include

main()

 {

   printf("Hello World!\n");

   printf("Hello World!\n");

   printf("Hello World!\n");

   printf("Hello World!\n");

   printf("Hello World!\n");

 }

Indeed, this does exactly what was asked. But now we up the bet and ask you to do the same job for 100 hellos or, if you're still willing to type that much code, maybe 1,000 Hello World's, 10,000 Hello World's, or whatever it takes you to realise this isn't a sensible method!

What you really need is some way of repeating the printf statements without having to write it out each time. The solution to this problem is the while loop or the do while loop.


The while and do while Loops

You can repeat any statement using either the while loop:

while(condition) compound statement;

or the do while loop:

do compound statement while(condition);

The condition is just a test to control how long you want the compound statement to carry on repeating.

Each line of a C program up to the semicolon is called a statement. The semicolon is the statement's terminator. The braces { and } which have appeared at the beginning and end of our program unit can also be used to group together related declarations and statements into a compound statement or a block.

In the case of the while loop before the compound statement is carried out the condition is checked, and if it is true the statement is obeyed one more time. If the condition turns out to be false, the looping isn't obeyed and the program moves on to the next statement. So you can see that the instruction really means while something or other is true keep on doing the statement.

In the case of the do while loop it will always execute the code within the loop at least once, since the condition controlling the loop is tested at the bottom of the loop. The do while loop repeats the instruction while the condition is true. If the condition turns out to be false, the looping isn't obeyed and the program moves on to the next statement.


Conditions or Logical Expressions

The only detail we need to clear up is what the condition (or Logical Expression) can be. How, for example, do we display 100 or 10,000 "Hello World!" messages? The condition can be any test of one value against another. For example:

a>0

is true if a contains a value greater than zero;

b<0

is true if b contains a value less than zero.

The only complication is that the test for 'something equals something else' uses the character sequence == and not =. That's right: a test for equality uses two equal-signs, as in a==0, while an assignment, as in a=0, uses one. This use of the double or single equal sign to mean slightly different things is a cause of many a program bug for beginner and expert alike!

So what about answering the question? What about the 100 "Hello World"s? Well, for the moment we know easily how to produce an infinite number of Hello Worlds! using while loop:

 

#include

  main()

   {

    while (1 == 1) printf("Hello World!\n");

   }

and using the do while loop:

 

#include

  main()

   {

    do

 

آموزش زبان c قسمت دهم:

      printf("Hello World!\n");

    while (1 == 1)

   }

If you type either of these programs in and run it you will find that your screen fills with a never ending list of "Hello World!"s. Why? Because the condition to keep the repeat going is ( 1 == 1 ), one equals one in plain English, which is always true! So how do we stop the loop? In some cases it could be by pulling the plug out - but usually you can stop an infinite loop by pressing Ctrl-Break or Ctrl-C.

An infinite loop is sometimes useful - I certainly hope the program controlling the nearest nuclear power station is an infinite loop that never receives a Ctrl-Break signal! Most loops, however, have to stop some time.

To solve our problem of printing 100 "Hello World!"s we need a counter and a test for when that counter reaches 100. A counter is a simple variable that has one added to it each time through the loop, using an instruction like this:

a=a+1;

This always confuses beginners, because they aren't used to seeing the variable on both sides of the equal-sign. All this means is that a has one added to it to produce a new value, and this value is stored back in the location called <B>a. If you're worried, try thinking about it as:

 

temp = a+l;

a    = temp;

 

The two approaches are more or less the same. C is a language where anything that's used often can be said concisely, so it lets you say "add one to a variable" using the shorter notation:

++a;

The double plus is read "increment a by one". Make sure you know that ++a; and a=a+1; are the same thing because you will often see both in typical C programs.

The increment operator ++ and the equivalent decrement operator --, can be used as either prefix (before the variable) or postfix (after the variable). Note: ++a increments a before using its value; whereas a++ which means use the value in a then increment the value stored in a.

Now it is easy to print "Hello World!" 100 times using the while loop:

 

#include

 main()

  {

   int count;

   count=0;

   while (count < 100)

    {

      ++count;

      printf("Hello World!\n");

    }

  }

[program]

or the do while loop:

 

#include

 main()

  {

   int count;

   count=0;

   do

    {

      ++count;

      printf("Hello, World!\n");

    } while (count < 100)

  }

[program]

Note: the use of the { and } to form a compound statement; all statements between the braces will be executed before the loop check is made.

The integer variable count is declared and then set to zero, ready to count the number of times we have gone round the loop. Each time round the loop the value of count is checked against 100. As long as it is less, the loop carries on. Each time the loop carries on, count is incremented and "Hello World!" is printed - so eventually count does reach 100 and the loop stops. These little programs are just a bit more subtle than you might think. Ask yourself, do they really print exactly 100 times? Ask yourself: what is the final value of count? If you want to make sure you are right change the printf to:

printf("count is %d",count);

and add a printf after the loop:

printf("final value is %d",count);

Make sure you understand why you get the results that you do. What would happen if you changed the initial value of count to be one rather than zero?


Looping the Loop

We have seen that any list of statements enclosed in curly brackets is treated as a single statement, a compound statement. So to repeat a list of statements all you have to do is put them inside a pair of curly brackets as in:

 

while (condition)

 {

   statementl;

   statement2;

   statement3;

 }

which repeats the list while the condition is true. Notice that the statements within the curly brackets have to be terminated by semicolons as usual. Notice also that as the while statement is a complete statement it too has to be terminated by a semi-colon - except for the influence of one other punctuation rule. You never have to follow a right curly bracket with a semi-colon. This rule was introduced to make C look tidier by avoiding things like

};};};}

at the end of a complicated program. You can write the semi-colon after the right bracket if you want to, but most C programmers don't. You can use a compound statement anywhere you can use a single statement.


The for Loop

The while, and do-while, loop is a completely general way of repeating a section of program over and over again - and you don't really need anything else but... The while loop repeats a list of instructions while some condition or other is true and often you want to repeat something a given number of times.

The traditional solution to this problem is to introduce a variable that is used to count the number of times that a loop has been repeated and use its value in the condition to end the loop. For example, the loop:

 

i=l;

while (i<10)

 {

   printf("%d \n",i);

   ++i;

 }

repeats while i is less than 10. As the ++ operator is used to add one to i each time through the loop you can see that i is a loop counter and eventually it will get bigger than 10, i.e. the loop will end.

The question is how many times does the loop go round? More specifically what values of i is the loop carried out for? If you run this program snippet you will find that it prints 1,2,3... and finishes at 10. That is, the loop repeats 10 times for values of i from 1 to 10. This sort of loop - one that runs from a starting value to a finishing value going up by one each time - is so common that nearly all programming languages provide special commands to implement it. In C this special type of loop can be implemented as a for loop.

 

for ( counter=start_value; counter <= finish_value; ++counter )

  compound statement

 

which is entirely equivalent to:

 

counter=start;

while (couner <= finish)

 {

  statements;

  ++counter;

 }

 

The condition operator <= should be interpreted as less than or equal too. We will be covering all of C's conditions , or logical expressions, in the next section.

For example to print the numbers 1 to 100 you could use:

for ( i=l; i <= 100; ++i ) printf("%d \n",i);

You can, of course repeat a longer list of instructions simply by using a compound statement.

The C for loop is much more flexible than this simple description. Indeed, many would be horrified at the way we have described the for loop without displaying its true generality, but keep in mind that there is more to come.

 

آموزش زبان c قسمت یازدهم:

In the meantime consider the following program, it does a temperature conversion, but it also introduces one or two new concepts:

  1. our counter does not have to be incremented (decremented) by 1; we can use any value.
  2. we can do calculations within the printf statement.

 

#include

 

main()

{

    int fahr;

 

    for ( fahr = 0 ; fahr <= 300 ; fahr = fahr + 20)

        printf("%4d %6.1f\n" , fahr , (5.0/9.0)*(fahr-32));

 

}

 

[program]

and here's another one for you to look at:

 

#include

 

main()

{

    int lower , upper , step;

    float fahr , celsius;

 

    lower = 0  ;

    upper = 300;

    step  = 20 ;

 

    fahr  = lower;

 

    while ( fahr <= upper ) {

                             celsius = (5.0 / 9.0) * (fahr - 32.0);

                             printf("%4.0f %6.1f\n" , fahr , celsius);

                             fahr = fahr + step;

                            }

}


 

 

Conditional Execution


Objectives

Having read this section you should be able to:

  1. Program control with if , if-else and switch structures
  2. have a better idea of what C understands as true and false.

Program Control

It is time to turn our attention to a different problem - conditional execution. We often need to be able to choose which set of instructions are obeyed according to a condition. For example, if you're keeping a total and you need to display the message 'OK' if the value is greater than zero you would need to write something like:

if (total>O) printf("OK");

This is perfectly reasonable English, if somewhat terse, but it is also perfectly good C. The if statement allows you to evaluate a > condition and only carry out the statement, or compound statement, that follows if the condition is true. In other words the printf will only be obeyed if the condition total > O is true.

If the condition is false then the program continues with the next instruction. In general the if statement is of the following form:

if (condition) statement;

and of course the statement can be a compound statement.

Here's an example program using two if statements:

 

 

#include

 

main()

{

    int a , b;

 

    do {

 

        printf("\nEnter first number: ");

        scanf("%d" , &a);

 

        printf("\nEnter second number: ");

        scanf("%d" , &b);

 

        if (a

        if (b

 

       } while (a < 999);

}

 

[program]

Here's another program using an if keyword and a compound statement or a block:

 

#include

 

main()

{

    int a , b;

 

    do {

 

        printf("\nEnter first number: ");

        scanf("%d" , &a);

 

        printf("\nEnter second number: ");

        scanf("%d" , &b);

 

        if (a

                  printf("\n\nFirst number is less than second\n");

                  printf("Their difference is : %d\n" , b-a);

                  printf("\n");

                 }

 

        printf("\n");

 

       } while (a < 999);

}

 

 

[program]

The if statement lets you execute or skip an instruction depending on the value of the condition. Another possibility is that you might want to select one of two possible statements - one to be obeyed when the condition is true and one to be obeyed when the condition is false. You can do this using the

if (condition) statement1;

else statement2;

form of the if statement.

In this case statement1 is carried out if the condition is true and statement2 if the condition is false.

Notice that it is certain that one of the two statements will be obeyed because the condition has to be either true or false! You may be puzzled by the semicolon at the end of the if part of the statement. The if (condition) statement1 part is one statement and the else statement2 part behaves like a second separate statement, so there has to be semi-colon terminating the first statement.


Logical Expressions

So far we have assumed that the way to write the conditions used in loops and if statements is so obvious that we don't need to look more closely. In fact there are a number of deviations from what you might expect. To compare two values you can use the standard symbols:

> 

(greater than)

< 

(less than)

>=

(for greater than or equal to )

<=

(for less than or equal to)

==

(to test for equality)

The reason for using two equal signs for equality is that the single equals sign always means store a value in a variable - i.e. it is the assignment operator. This causes beginners lots of problems because they tend to write:

if (a = 10) instead of if (a == 10)

The situation is made worse by the fact that the statement if (a = 10) is legal and causes no compiler error messages! It may even appear to work at first

آموزش زبان c قسمت دوازدهم:

because, due to a logical quirk of C, the assignment actually evaluates to the value being assigned and a non-zero value is treated as true (see below). Confused? I agree it is confusing, but it gets easier. . .

Just as the equals condition is written differently from what you might expect so the non-equals sign looks a little odd. You write not equals as !=. For example:

if (a != 0)

is 'if a is not equal to zero'.

An example program showing the if else construction now follows:

 

#include

 

main ()

 {

   int num1, num2;

 

   printf("\nEnter first number ");

   scanf("%d",&num1);

 

   printf("\nEnter second number ");

   scanf("%d",&num2);

 

   if (num2 ==0) printf("\n\nCannot devide by zero\n\n");

   else          printf("\n\nAnswer is %d\n\n",num1/num2);

 }

 

[program]

This program uses an if and else statement to prevent division by 0 from occurring.


True and False in C

Now we come to an advanced trick which you do need to know about, but if it only confuses you, come back to this bit later. Most experienced C programmers would wince at the expression if(a!=0).

The reason is that in the C programming language dosen't have a concept of a Boolean variable, i.e. a type class that can be either true or false. Why bother when we can use numerical values. In C true is represented by any numeric value not equal to 0 and false is represented by 0. This fact is usually well hidden and can be ignored, but it does allow you to write

if(a != 0) just as if(a)

because if a isn't zero then this also acts as the value true. It is debatable if this sort of shortcut is worth the three characters it saves. Reading something like

if(!done)

as 'if not done' is clear, but if(!total) is more dubious.


Using break and continue Within Loops

The break statement allows you to exit a loop from any point within its body, bypassing its normal termination expression. When the break statement is encountered inside a loop, the loop is immediately terminated, and program control resumes at the next statement following the loop. The break statement can be used with all three of C's loops. You can have as many statements within a loop as you desire. It is generally best to use the break for special purposes, not as your normal loop exit. break is also used in conjunction with functions and case statements which will be covered in later sections.

The continue statement is somewhat the opposite of the break statement. It forces the next iteration of the loop to take place, skipping any code in between itself and the test condition of the loop. In while and do-while loops, a continue statement will cause control to go directly to the test condition and then continue the looping process. In the case of the for loop, the increment part of the loop continues. One good use of continue is to restart a statement sequence when an error occurs.

 

#include

 

main()

{

    int x ;

 

    for ( x=0 ; x<=100 ; x++) {

                               if (x%2) continue;

                               printf("%d\n" , x);

                              }

}

 

 

[program]

Here we have used C's modulus operator: %. A expression:

a % b

produces the remainder when a is divided by b; and zero when there is no remainder.

Here's an example of a use for the break statement:

 

#include

 

main()

{

    int t ;

 

    for ( ; ; ) {

                 scanf("%d" , &t)   ;

                 if ( t==10 ) break ;

                }

    printf("End of an infinite loop...\n");

 

}

 

[program]


Select Paths with switch

While if is good for choosing between two alternatives, it quickly becomes cumbersome when several alternatives are needed. C's solution to this problem is the switch statement. The switch statement is C's multiple selection statement. It is used to select one of several alternative paths in program execution and works like this: A variable is successively tested against a list of integer or character constants. When a match is found, the statement sequence associated with the match is executed. The general form of the switch statement is:

 

switch(expression)

{

  case constant1:   statement sequence; break;

  case constant2:   statement sequence; break;

  case constant3:   statement sequence; break;

  .

  .

  .

  default:   statement sequence; break;

}

 

Each case is labelled by one, or more, constant expressions (or integer-valued constants). The default statement sequence is performed if no matches are found. The default is optional. If all matches fail and default is absent, no action takes place.

When a match is found, the statement sequence associated with that case are executed until break is encountered.

An example program follows:

 

#include

 

main()

 {

  int i;

 

  printf("Enter a number between 1 and 4");

  scanf("%d",&i);

 

  switch (i)

   {

     case 1:

      printf("one");

      break;

     case 2:

      printf("two");

      break;

     case 3:

      printf("three");

      break;

     case 4:

      printf("four");

      break;

     default:

      printf("unrecognized number");

   }    /* end of switch */

 

 }

 

[program]

 

آموزش زبان c قسمت سیزدهم:

This simple program recognizes the numbers 1 to 4 and prints the name of the one you enter. The switch statement differs from if, in that switch can only test for equality, whereas the if conditional expression can be of any type. Also switch will work with only int and char types. You cannot for example, use floating-point numbers. If the statement sequence includes more than one statement they will have to be enclosed with {} to form a compound statement.


 

 

Structure and Nesting


Objectives

This section brings together the various looping mechanisms available to the C programmer with the program control constructs we met in the last section.

We also demonstrates a neat trick with random numbers.


It is one of the great discoveries of programming that you can write any program using just simple while loops and if statements. You don't need any other control statements at all. Of course it might be nice to include some other types of control statement to make life easy - for example, you don't need the for loop, but it is good to have! So as long as you understand the if and the while loop in one form or another you can write any program you want to.

If you think that a loop and an if statement are not much to build programs then you are missing an important point. It's not just the statements you have, but the way you can put them together. You can include an if statement within a loop, loops within loops are also OK, as are loops in ifs, and ifs in ifs and so on. This putting one control statement inside another is called nesting and it is really what allows you to make a program as complicated as you like.


 

Think of a number

Now let's have a go at writing the following program: 'It thinks of a number in the range 0 to 99 and then asks the user to guess it'. This sounds complicated, especially the 'thinks of a number' part, but all you need to know is that the statement:

r = rand()

will store a random number in the integer variable r. The standard library function rand() randomly picks a number within the range 0 to 32767, but this might vary from machine to machine. Look upon rand() as being a large dice.

Our problem is to select a number between 0 and 99 and not between 0 and 32767. How can we get our random number to within our range? The rand() function will produce numbers such as:

2567

134

20678

15789

32001

15987

etc...

 

If you look at the last two digits of all of these numbers they would form our random set! To select just these numbers we can use an arithmetic calculation of the following form:

r = rand() % 100

That is, to get the number into the right range you simply take the remainder on dividing by 100, ie a value in the range 0 to 99. You should remember this neat programming trick, you'll be surprised how often it is required.

Our solution to the problem is as follows:

 

#include

 

main()

 {

   int target;

   int guess;

   int again;

 

   printf("\n Do you want to guess a number 1 =Yes, 0=No ");

   scanf("%d",&again);

 

   while (again)

    {

      target = rand() % 100;

      guess  = target + l;

 

      while(target!=guess)

       {

         printf('\n What is your guess ? ");

         scanf("%d",&guess);

 

         if (target>guess) printf("Too low");

         else printf("Too high");

       }

 

      printf("\n Well done you got it! \n");

      printf("\nDo you want to guess a number 1=Yes, 0=No");

      scanf("%d".&again);

    }

 }

[program]

This looks like a very long and complicated program, but it isn't. Essentially it used two loops and an if/else which in English could be summarised as:

 

 

while(again) {

  think of a number

  while (user hasn't guessed it)

   {

     get users guess.

     if (target < guess) tell the user the guess is low

     else                tell the user the guess is high

   }

}

The integer variable again is used to indicate that the user wants to carry on playing. If it is 0 then the loop stops so 0 = No, and 1, or any other non-zero value, = Yes.

If you try this program out you will discover that it has a slight flaw - not so much a bug, more a feature. If the user guesses the correct value the program still tells the user that the guess is too high and then congratulates them that they have the correct value. Such problems with how loops end are common and you have to pay attention to details such as this. There are a number of possible solutions, but the most straight forward is to change the inner loop so that the first guess is asked for before the loop begins. This shifts the test for the loop to stop to before the test for a high or low guess:

 

 

#include

 

main()

 

 

آموزش زبان c قسمت چهاردهم:

{

   int target;

   int guess;

   int again;

 

   printf("\n Do you want to guess a number 1 =Yes, 0=No ");

   scanf("%d",&again);

 

   while (again)

    {

      target = rand() % 100;

 

      printf('\n What is your guess ? ");

      scanf("%d",&guess);

 

      while(target!=guess)

       {

         if (target>guess) printf("Too low");

         else printf("Too high");

         printf('\n What is your guess ? ");

         scanf("%d",&guess);

       }

 

      printf("\n Well done you got it! \n");

      printf("\n Do you want to guess a number 1=Yes, 0=No");

      scanf("%d".&again);

    }

 }

[program]

If you want to be sure that you understand what is going on here, ask yourself why the line:

guess = target + 1;

was necessary in the first version of the program and not in the second?


 

 

Functions and Prototypes


Objectives

Having read this section you should be able to:

  1. program using correctly defined C functions
  2. pass the value of local variables into your C functions

Functions - C's Building Blocks

Some programmers might consider it a bit early to introduce the C function - but we think you can't get to it soon enough. It isn't a difficult idea and it is incredibly useful. You could say that you only really start to find out what C programming is all about when you start using functions.

C functions are the equivalent of what in other languages would be called subroutines or procedures. If you are familiar with another language you also need to know that C only has functions, so don't spend time looking for the definition of subroutines or procedures - in C the function does everything!

A function is simply a chunk of C code (statements) that you have grouped together and given a name. The value of doing this is that you can use that "chunk" of code repeatedly simply by writing its name. For example, if you want to create a function that prints the word "Hello" on the screen and adds one to variable called total then the chunk of C code that you want to turn into a function is just:

 

printf("Hello");

total = total + l;

 

To turn it into a function you simply wrap the code in a pair of curly brackets to convert it into a single compound statement and write the name that you want to give it in front of the brackets:

 

demo()

 {

  printf("Hello");

  total = total + 1;

 }

 

Don't worry for now about the curved brackets after the function's name. Once you have defined your function you can use it within a program:

 

main()

 {

  demo();

 }

 

In this program the instruction demo (); is entirely equivalent to writing out all of the statements in the function. What we have done is to create an new C function and this, of course, is the power of functions. When you are first introduced to the idea of functions, or their equivalent in other languages, it is easy to fall into the trap of thinking that they are only useful when you want to use a block of code more than once.

Functions are useful here but they have a more important purpose. If you are creating a long program then functions allow you to split it into "bite-sized" chunks which you can work on in isolation. As every C programmer knows, "functions are the building blocks of programs."


Functions and Local Variables

Now that the philosophy session is over we have to return to the details - because as it stands the demo function will not work. The problem is that the variable total isn't declared anywhere. A function is a complete program sub-unit in its own right and you can declare variables within it just as you can within the main program. If you look at the main program we have been using you will notice it is in fact a function that just happens to be called "main"! So to make demo work we have to add the declaration of the variable total:

 

demo()

 {

  int total;

  printf("Hello");

  total=total+1;

 }

 

Now this raises the question of where exactly total is a valid variable. You can certainly use total within the function that declares it - this much seems reasonable - but what about other functions and, in particular, what about the main program? The simple answer is that total is a variable that belongs to the demo function. It cannot be used in other functions, it doesn't even exist in other functions and it certainly has nothing to do with any variable of the same name that you declare within other functions.

This is what we hinted at when we said that functions were isolated chunks of code. Their isolation is such that variables declared within the function can only be used within that function. These variables are known as local variables and as their name suggests are local to the function they have been declared in. If you are used to a language where every variable is usable all the time this might seem silly and restrictive - but it isn't. It's what makes it possible to break a large program down into smaller and more manageable chunks.

The fact that total is only usable within the demo function is one thing - but notice we said that it only existed within this function, which is a more subtle point. The variables that a function declares are created when the function is started and destroyed when the function is finished. So if the intention is to use total to count the number of times the >demo function is used - forget it! Each time demo is used the variable total is created afresh, and at the end of the function the variable goes up in a puff of smoke along with its value. So no matter how many times you run demo total will only ever reach a value of 1, assuming that it's initialised to 0.


Making The Connections

Functions are isolated, and whats more nothing survives after they have finished. Put like this a function doesn't seem to be that useful because you can't get data values in, you can't get data values out, and they don't remember anything that happens to them!

To be useful there has to be a way of getting data into and out of a function, and this is the role of the curved brackets. You can define special variables called parameters which are used to carry data values into a function. Parameters are listed and declared in between the () brackets in the function's definition. For example: