Answer to Question #308233 in C for ahmed

Question #308233

Write a program to reverse a number.


1
Expert's answer
2022-03-16T10:25:07-0400
#include <stdio.h>

int main()
{
    long num, revers;
    int digit;
    revers = 0;
    printf("Enter number: ");
    scanf("%ld", &num);
    while (num > 0)
    {
        digit = num % 10;
        num = num / 10;
        revers = revers * 10;
        revers = revers + digit;
    }
    printf("\n\nRevers: %ld\n", revers);
    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS