Saturday, November 7, 2009

Reverse The Digits of Any Number | C Programming

//wap to reverse the digits of any number
#include
#include
#include
void main()
{
int i,n=, r=0, s=0, c=0, rev=0, x; //students are advised to use
clrscr(); // “long” instead of “int” so as to use high figure no
printf(“\n\n enter a number: “);
scanf(“%d”,&n);
x=n;
while(n!=0){ // to count the digits
n=n/10;
c=c+1;}
printf(“\n The total digits in number : %d”,c);
while(x!=0){ //decrement of the power of 10
c=c-1;
r=x%10;
x=x/10;
rev=rev + r*pow(10,c);}

printf(“\n\n\a\tThe reverse is :%d”,rev);
getch();
}
o/p→
enter a number : 12345
The reverse is : 54321





No comments:

Post a Comment