CMSC 104, Section 105
Increment ++ and Decrement -- Problems
What do the following c programs output:
#include
main()
{
int n = 0;
while ( ++n < 11 )
{
printf("\t %2d \t %5d \t %5d \t %6d \n",n,10 * n,100 * n,1000 * n);
}
return 0;
}
#include
main()
{
int c;
c = 5;
printf(" %d \n " , c);
printf(" %d \n " , --c);
printf(" %d \n \n " , c);
c = 5;
printf(" %d \n " , c);
printf(" %d \n " , c--);
printf(" %d \n \n " , c);
c = 5;
printf(" %d \n " , c);
printf(" %d \n " , c++);
printf(" %d \n " , ++c);
printf(" %d \n \n" , c);
return 0;
}
#include
main()
{
int i = 0;
while ( ++i < 11 )
{
printf( "%d " , i );
}
return 0;
}
#include
main()
{
int i = 0;
while ( i++ < 11 )
{
printf( "%d " , i );
}
return 0;
}