C program to reverse a given number
kw.c
#include <stdio.h>
int main()
{
    int n, temp;
    printf("———————————————————————————————————————————");
    printf("\nProgram to reverse a given number");
    printf("\n———————————————————————————————————————————");
    printf("\nEnter the number ");
    scanf("%d", &n);
    if (n < 10)
    {
        printf("\nUnable to reverse the negative and single-digit number.");
    }
    else
    {
        printf("\nThe reverse number is ");
        while (n / 10 != 0)
        {
            temp = n % 10;
            n = n / 10;
            printf("%d", temp);
        }
        printf("%d", n);
    }
    printf("\n———————————————————————————————————————————\n");
    return 0;
}
Output
kodingwindow@kw:~$ gcc kw.c
kodingwindow@kw:~$ ./a.out ——————————————————————————————————————————— Program to reverse a given number ——————————————————————————————————————————— Enter the number 5 Unable to reverse the negative and single-digit number. ——————————————————————————————————————————— kodingwindow@kw:~$ ./a.out ——————————————————————————————————————————— Program to reverse a given number ——————————————————————————————————————————— Enter the number 65535 The reverse number is 53556 ——————————————————————————————————————————— kodingwindow@kw:~$
Advertisement