In: Computer Science
#include<stdio.h>
int main()
{
int i;
/* Prints "for loop" and then uses a for statement to
count from 1 to 100. */
printf("for loop\n");
for(i=1;i<=100;i++)
{
printf("%d",i);
/*
Using a nested if/else statement or
a switch in one of the loops , print to the screen if a number
is:
Less than or equal to 10 (print
less than 11 to the screen)
Greater than or equal to 11 but
less than 20. (print between 10 and 20 to the screen)
Greater than 21 (print greater than
21 to the screen)
*/
if(i<=10)
{
printf("\tless
than 11");
}
else if(i>=11 &&
i<20)
{
printf("\tbetween 10 and 20");
}
else if(i>21)
{
printf("\tGreater then 21");
}
printf("\n");
}
/* Prints "while loop" and then uses a while statement
to count from 1 to 100. */
printf("\nwhile loop\n");
i=1;
while(i<=100)
{
printf("%d\n",i++);
}
/* Prints "do while loop" and then use a do while
statement to count from 1 to 100. */
printf("\ndo while loop\n");
i=1;
do
{
printf("%d\n",i++);
}while(i<=100);
}