Recent

recentposts

While loop

  The while loop

Syntax:

while( test-condition )

  {

  Statement to be executed ;

  Update-condition ;  

  }


while loop

 


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

#include<iostream.h>

#include<conio.h>


void main() {


clrscr() ;

int i = 1 ;


while( i<100 )

  {


  cout<<i ;

  i = i+1 ;


  }

getch() ;

}

 

Program to print the even numbers using 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 ;


while ( i < ending )

{

  if ( i%2==0 )

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

  

  i = i+1 ;

}


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 ;


while ( number < 50 )

   

     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 ;

   }


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