Sunday, December 18, 2022

C programming. How to print reverse of a number.

 C Program to print reverse of a number.

#include<stdio.h>
int main() {
    int num, rev=0, rem;
    printf("Enter a number : ");
    scanf("%d",&num);
    while (num>0){
        rem = num%10;
        rev = rev*10+rem;
        num /= 10;
    }
    printf("The reverse of the number is : %d",rev);
    return 0;
}

The output should be like this...

                    Enter a number : 12345
                    The reverse of the number is : 54321
                    

No comments:

Post a Comment

Selection Sort Using C programming.

Selection sort is a simple and efficient sorting algorithm that works by repeatedly selecting the smallest (or largest) element from the un...