Reverse Digits of Number in C Language
Write a Reverse Digits of Number in C to reverse the digits of a given integer. User needs to provide the number initially to the program,then program will reverse the digits of number.
Reverse Digits of Number in C Program will divide the number by 10 continuously to get the digits as separate entities. After separating all digits it will rebuild the number by multiplying digits by 10*n to get reverse number.
Reverse Digits of Number in C Code
#include<stdio.h> #include<conio.h> void main() { int num,rev=0,dig; clrscr(); //accept the number to be reversed printf(“Enter number:\t”); scanf(“%d”,&num); while(num>0) { dig=num%10; rev=(rev*10)+dig; num=num/10; } printf(“Reversal of number:=%d “,rev); getch(); }
Leave a Reply