Name: ________________________ Netid: _______________ Section: _______
a) __________________________________________
b) __________________________________________
c) __________________________________________
2. Common errors in writing if, nested if and switch statements.
#include <stdio.h>
void main(void){
int
no;
int
ir, hr;
no = -1;
if (no >
0); /* ; here means end of
statement
so the printf immediately below is not
part of the if
*/
printf("positive!\n");
no = 0;
if ( no =
1) /* == means test for equality =
means
assign. If no is assigned 1 that means true in C. */
printf(" equal!\n");
else
printf("not
equal!\n");
no = 2;
switch(no){
case 1:
printf("one ");
case
2: printf("two
"); /* note that the break
statements
are missing */
case
3: printf("three ");
default:
printf( "not valid! " );
}
printf("\n");
}
Write the output of the program (above).
d) __________________________________________
e) _________________________________________
f) _________________________________________
1. Complete the algorithm for the change
program.