Page 58 - Modular_V1.1_Flipbook
P. 58
while (x = x + 1)
while (n--)
while (count += i)
Program 4: To input any number and print it in reverse order using while loop. The input number
must be positive.
#include<iostream.h>
#include<conio.h> Output 1:
Enter the number to be
void main()
reversed: - 1543
{
The number must be positive
long int n = 0, digit; Output 2:
cout<<”Enter the number to be reversed: “; Enter the number to be
reversed: 654321
cin>>n;
The reverse of number
while (n <= 0)
654321 is: 123456
{
cout<< “The number must be positive \n”;
break;
}
cout<<”The reverse of number “ << n << “ is: “;
while (n != 0 && n>0)
{
digit = n % 10;
cout<<digit;
n = n / 10;
}
getch();
}
THE DO-WHILE LOOP
The do-while loop is similar to the while loop. The only difference is that with do-while loop,
the condition is stated at the end of the loop. This ensures that the body of the loop executes at
least once. The syntax of the do-while loop is:
do
{
statements;
}
while (condition);
56 Touchpad MODULAR (Version 1.1)-X

