Recent

recentposts

do-while loop

The do-while loop

Syntax:

do{

   statement to be executed  ;

   update-condition   ;

}

while( test-condition );


do-while


 

Program to print the odd numbers up to 100 using do-while loop.

#include<iostream.h>

#include<conio.h>


void main() {


clrscr() ;

int i = 1 ;


do {

  cout<<i ;

  i=i+1 ;

}

while( i<100 ) ;


getch() ;

}

 

Program to print the even numbers using do-while loop and ranges are taken by user.

#include<iostream.h>

#include<conio.h>


void main() {


clrscr() ;

int i, starting , ending ;


cout<<”\n Enter the starting range of Even number series. ” ;

cin>>starting ;

cout<<”\n Enter the end point of Even number series. ” ;

cin>>ending ;


i = starting ;

do {

  if ( i%2==0 )

  {  cout<<”Even number = ”<<i ;   }

  

  i = i+1 ;

}

while ( i < ending ) ;


getch() ;

}

 

Program to identify Prime Number between 1 to 50 using while loop.

#include<iostream.h>

#include<conio.h>


void main() {


clrscr() ;

int number, counter , divisor ;


number=1 ;

do {

   counter = 0 ;

   divisor = number ;

   

   while( divisor>0 )

{

   if ( number % divisor ==0 )

   {  counter++ ;  }

   else

   {   continue ;   }

   divisor-- ;

}


if ( counter == 2 )

{  cout<<”\n Prime Number is = ”<< number ;  }


number = number + 1 ;

}

while ( number < 50 ) ;


getch() ;

}


___________________________________________________________________________________

SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment

Please give your valuable suggestions