Write a program to reverse any number


2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Write a program to reverse any number
// Eg: 4 -> 4, 1234 -> 4321

#include
int main(){
    int n;
    printf("Enter a positive integer:");
    scanf("%d",&n); // input from user
    while(n<0){ printf("Please enter positive integer only:"); scanf("%d",&n); } int rev=0; while(n>0){
         rev = rev*10+n%10; // calculating reverse of given integer
         n = n/10;
    }
    printf("Reverse of given number: %d",rev);
    getch();
}

No comments:

Post a Comment