Ads (300 x 250)

Breaking News

do...while loop in C

 do...while loop in C

Do...while loop is post-test loop or button-test loop.because it test the loop condition at the top of the loop, the do...while loop in C programming excute atleast one time whether the condition is  true or false.

do...while loop is similar to a while loop, The do-while loop is mostly used in menu-driven programs 

Syntax

The syntax of a do...while loop in C programming language is −



           
            do {
            statement;
            } while( condition );
            

We noticed In do… while at first loop is executed then the condition check
If the condition is true, then jumps back up to do, and the statement in the loop executes again. This process continuing until the given condition becomes false.

Flow chart:-


do...while loop in C

Example:-

Write a C program to find the factors of a positive integer using DO WHILE loop


           

            #include<stdio.h>

            Void main()

            {

            Int a,i=1,f=1;  //variable declaration int maens integer type variable

            Printf(“\n Enter your Number:”);  

            Scanf(“%d”,&a);

            //LOOP TO CALCULATE THE FACTORIAL OF A NUMBER

            Do

            {

            F=f*I;

            I++;

            }while(i<=n);

            

            Printf(“\n The Factorial of %d is %d”,n,f);  

            }

            

            



Output:-
Hblearner
Factor of 12


No comments