DO NOT MISS

Ads

Tuesday, 2 August 2016

do-while statements with C-Programs



The types of loop where the test condition is stated at the end of the body of the loop, are know as the exit controlled loops.

The fallowing is the example for entry exit looping control statement.




It is an alternative form of while loop. The only difference between while and do while is the minimum number of execution of ‘while’ is ‘0’. For minimum no of execution of ‘do-while’ is ‘1”.



Syntax:-

do
{

statement;

} while(condition);


Flow chart:-



Note:-
1. First it executes the no. of statements 
2. Then goes to condition for 2nd reputation.
3. If the condition is true it's again executes the true statements.
4. This process will be continued until the specified condition will be false.

* Write a program to print find the factorial of the given number.


#include<stdio.h> 

#include<conio.h> 



void main() 



     { 


          int i=1,fact=1,n; 
          clrscr(); 

          printf("enter a no:"); 
          scanf("%d",&n); 

          do 

              { 

                       fact=fact*i; 
                       i++; 

              } 

          while(i<=n); 
          printf("%d",fact); 

          getch(); 

     }

Output:-


Explanation:-
5!(Factorial) =5 * 4 * 3 * 2 * 1 =120
4!(Factorial) = 4 * 3 * 2 * 1 =24
3!(Factorial) = 3 * 2 * 1 =6
______________________________________________________
______________________________________________________
_____________________________________________________
___________________________________________________

Greataims

 
Copyright © 2016 Computersadda. Designed by @ Computersadda Team - Published By Greataims