//In this program code the user will be prompted to enter a number (integer), and the program will //print the reverse of that.
#include<iostream> //For Input/Output Stream
#include<conio.h> //For clrscr & getche
using namespace std; //using the standard namespace
void main()
{
clrscr(); //clearing the console screen
long int x,y,s=0; //value of 's' is initialized with a value of '0'
cout<<"Enter no.:";
cin>>x; //user input the value of 'x'
while(x!=0) //run until the value of 'x' is not equal to '0'
{
y=x%10; //getting the remainder from 'x' when divided by '10' & storing it into 'y'
x=x/10; //dividing the value of 'x' by '10' & storing the quotient (integer) in 'x'
s=s*10+y; //storing the reversed weighted result in 's'
}
cout<<"\nThe reverse no.="<<s; //printing the reversed number
getche(); //to exit the program after a keystroke
}
#include<iostream> //For Input/Output Stream
#include<conio.h> //For clrscr & getche
using namespace std; //using the standard namespace
void main()
{
clrscr(); //clearing the console screen
long int x,y,s=0; //value of 's' is initialized with a value of '0'
cout<<"Enter no.:";
cin>>x; //user input the value of 'x'
while(x!=0) //run until the value of 'x' is not equal to '0'
{
y=x%10; //getting the remainder from 'x' when divided by '10' & storing it into 'y'
x=x/10; //dividing the value of 'x' by '10' & storing the quotient (integer) in 'x'
s=s*10+y; //storing the reversed weighted result in 's'
}
cout<<"\nThe reverse no.="<<s; //printing the reversed number
getche(); //to exit the program after a keystroke
}
3 comments:
#include
#include
main()
{
int i,p;
printf("enter any no.:");
scanf("%d",&i);
while(i>0)
{
p=i%10;
printf("%d",p);
i=i/10;
}
main()
{
int i,p;
printf("enter any no.:");
scanf("%d",&i);
while(i>0)
{
p=i%10;
printf("%d",p);
i=i/10;
}
#include
#include
main()
{
int i,p;
printf("enter any no.:");
scanf("%d",&i);
while(i>0)
{
p=i%10;
printf("%d",p);
i=i/10;
}
Post a Comment