//Write a program to print reverse number of given number using while loop #include<stdio.h> #include<conio.h> void main() { int n,a,r=0; clrscr(); printf("Enter any number:\n"); scanf("%d"&n); while(n)//run loop until n have some value { a=n%10;//from this we get last digit r=r*10+a; n=n/10; } printf("Reverse = %d",r); getch(); } /*For example we input a number 123 then a = 123%10 = 3 r = 0*10 + 3 = 3 n = 123/10 = 12 a = 12%10 = 2 r = 3*10 + 2 = 32 n = 12/10 = 1 a = 1%10 = 1 r = 32*10 + 1 = 321 n = 1/10 = 0 while n become zero while loop stop then print r=321 which is reverse of 123.*/
Comments
Post a Comment