LOOP CONTROL STRUCTURE IN C
Looping is a repetitive structure.In looping a group of structures are executed until some condition has been satisfied. In looping a group of statements are executed until some condition has been satisfied.In C following loop structure are available:
- for loop
- while loop
- do-while loop
1. for loop
For loop is very simple loop structure in C.In for loop we can specify initialization expression , Condition expression and increment expression in a single statement. It is also called short cut loop.
test expression;
update expression;)
body-of-the-loop;
for(i=1;i<=10;i++)
printf("\n%d",i);
getch();
test expression 1 test expression 2;
update expression 1 update expression 2)
for( ; ;)--infinite
loop-body;
while(i<=10)
{
printf("%d",i);
i++;
}
syntax: while (boolean) statement 1;
example while(1);
while(0);
{
statements;
}while(test-condition);
do
{
printf("%d\n",i);
}while(i<10);
PRACTICE QUESTIONS:
1. Write a program to display count from 0 to 9 by using For Loop | while loop | do while loop and Analysis which is the best approach to do.
2. Write a program to display even no , above 20 & below 40 by using For Loop | while loop | do while loop and Analysis which is the best approach to do.
3. Write a program to find average by using For Loop | while loop | do while loop and Analysis which is the best approach to do.
4. Write a program to find mirror image of a number by using For Loop | while loop | do while loop and Analysis which is the best approach to do.
5. Write a program to display sum of digits of a number by using For Loop | while loop | do while loop and Analysis which is the best approach to do.
6. Write a program to find out odd numbers form 1 to 100 by using For Loop | while loop | do while loop and Analysis which is the best approach to do.
7. Write a program to print out the even number form 1 to 100 by using For Loop | while loop | do while loop and Analysis which is the best approach to do.
8. Write a program to reverse the digits of any given number by using For Loop | while loop | do while loop and Analysis which is the best approach to do.
9. Write a program for Fibonacci series by using For Loop | while loop | do while loop and Analysis which is the best approach to do.
10. Write a program to print out the value of the following series.
a. SUM = 1 + 2 +3 + 4 + ....... + 20
b. SUM = 20 + 19 + 18 + 17 ------ + 1
No comments:
Post a Comment