do-while loop:

 v do-while loop:

It is use to execute the block of statement repeatedly till the condition is True.

Syntax:

do

{

            Statement 1;

            Statement 2;

            .

            .                                           Block of statements

            .

            .

            Statement n;

            Increment/Decrement loop counter;

 } while(Condition);

 

            Statement x;

            Statement y;

                       

Flowchart

 


 

§  It is exit control loop which execute block statement first then check the condition.

§  The body of loop start with keyword do and end with while condition.

§  It executes block of statement at list one time and it test condition, if condition is True then loop continue.

§  This repeated execution of the body of loop continues until the test condition does not False.

§  When condition is False the control will transfer out of loop and then execute statement x, statement y.

 

 

Program: Write a program to find odd numbers up to n number.

 

/* Prog no-11 Program to print a odd numbers up to n number */

#include <stdio.h>

#include <conio.h>

 

void main()

{

                int i,n;

 

                clrscr();

                i=1;

                printf("\nOdd nubers print up to n number\n Give n number : ");

                scanf("%d",&n);

 

                do

                {

                        printf("\n%d",i);

                        i=i+2;

 

                }while(i<=n)

 

                getch();

}

           

Output:

 


Program: Write a program to print Fibonacci series.

 

/* Prog no-12 Program to print Fibonacci series */

#include <stdio.h>

#include <conio.h>

 

void main()

{

                int n,num1,num2,sum,i;

                num1=2;

                num2=3;

                i=1;

 

                clrscr();

 

                printf("\nEnter n th number : ");

                scanf("%d",&n);

 

                do

                {

                        printf("\n%d",i);

                        i=i+2;

 

                }while(i<=n);

 

                getch();

}

Output:

 


Post a Comment

0 Comments