- a.TRUE
b.TRUE
c.TRUE. Notice that there is a single equals sign, making the ifan assignment
instead of a relation.
d.TRUE - The following is one possible answer:
if( age < 21 )
printf( “You are not an adult” );
else if( age >= 65 )
printf( “You are a senior citizen!”);
else
printf( “You are an adult” ); - This program has four problems. The first is on line 3. The assignment statement
should end with a semicolon, not a colon. The second problem is the semicolon at
the end of the ifstatement on line 6. The third problem is a common one: The
assignment operator (=) is used rather than the relational operator (==) in the if
statement. The final problem is the word otherwiseon line 8. This should be else.
Here is the corrected code:
/ a program with problems... /
#include <stdio.h>
int x = 1;
int main( void )
{
if( x == 1)
printf(“ x equals 1” );
else
printf(“ x does not equal 1”);
return 0;
}
Answers for Day 5
Quiz
- Yes! (Well, OK, this is a trick question, but you had better answer “yes” if you
want to become a good C programmer.) - Structured programming takes a complex programming problem and breaks it into
a number of simpler tasks that are easier to handle one at a time. - After you’ve broken your program into a number of simpler tasks, you can write a
function to perform each task.
836 Appendix F
49 448201x-APP F 2/5/04 1:16 PM Page 836