C++ while loop

while loop is the simplest form of loop, and it is entry controlled loop statement.

Syntax:

while(test condition)

{

Body of loop

}

At the first, condition is evaluated and if it is true then the body of loop is executed and then again the condition is evaluated and if it is true then the body of loop executed again.  This process goes again and again until the condition is not false. If the condition goes false then the control is exit out of loop.

 Program:

/*78.PROGRAM TO FIND REVERSE OF A NUMBER*/

#include<iostream.h>

#include<conio.h>

void main()

{

int n,rev=0,rem,temp;

clrscr();

cout<<“Enter any number: “;

cin>>n;

temp=n;

while(temp>0)

{

rem=temp%10;

temp=temp/10;

rev=rev*10+rem;

}

cout<<“Reverse of “<<n <<“is “<<rev;

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *