Learn How to Program in Cby Dr. Kristin Switala
|
|
Review: Conditionals (b)
Instructions: Think about each question and write the answer in your notebook.
General Questions
1. What does && mean?
2. What does || mean?
3. What does ! mean?
Special Operators
1. Fix the errors in this C source code. There are 2 errors.
|
#include <stdio.h>
void main( )
{
int born;
printf("\nWhat year were you born? ");
scanf("%d", &born);
if((born > 1956) & (born > 1969))
printf("\nYou were born during the height of Soviet space exploration.");
else
printf("\nYou were born when the US led the space race.");
}
|
2. Fix the errors in this C source code. There are 2 errors.
|
#include <stdio.h>
void main( )
{
int age;
int hubble = 1990;
int older;
printf("\nWhat year were your born? ");
scanf("%d", &age);
older = age < hubble ! age : hubble;
if(older = age)
printf("\nYou are older than the Hubble Space Telescope.");
else
printf("\nThe Hubble Space Telescope is older than you.");
}
|
|
|