C Programming Tutorial 03 Question
C Programming Tutorial 03 Question
Tutorial 3
int a=0;
do
{
printf(careful\n);
a++;
}
while(a>5);
int a=1;
while (a<4)
{
printf("This is the outer loop\n");
a++;
while (a<=25)
{
break;
printf("This prints 25 times\n");}
}
}
5. Find the error in each of the following (Note: there may be more than one error):
a. The following code should output the odd integers from 999 to 1:
b. The following code should output the even integers from 2 to 100:
counter = 2;
Do
{
if ( counter % 2 == 0 )
printf( "%u\n", counter );
counter += 2;
}
While ( counter < 100 );
c. The following code should sum the integers from 100 to 150 (assume total is
initialized to 0):
if (num==1)
{ printf(alpha);}
else if (num ==2)
{printf(beta);}
else if (num ==3)
{printf(gamma);}
else
{printf(other);}
7. Can the following conditional operator be rewritten as an if-else statement? If so, rewrite
it as one.
ans = (a == b)? c + 2 : c + 3;
8. State which values of the control variable x are printed by each of the following for
statements:
d) for ( x = 1; x <= 5; x += 7 )
printf( "%u\n", x );
a. 1, 2, 3, 4, 5, 6, 7
b. 3, 8, 13, 18, 23
c. 20, 14, 8, 2, -4, -10
d. 19, 27, 35, 43, 51
10. Using the precedence table, determine whether each of the following statements
produces a True or False result. After this, you should really appreciate the abundant
use of parentheses!
a. 5 = = 4 + 1 | | 7 * 2! = 12 1 && 5 = = 8 / 2
b. 8 + 9! = 6 1 | | 10 % 2! = 5 + 0
c. 17 1 > 15 + 1 && 0 + 2 = 1 = = | | 4! =1
d. 409 * 0! = 1 * 409 + 0 | | 1 + 8 * 2 >= 17