C program to reverse a given integer

Discussion on data structures & algorithms, programming languages, computer science and more
doctorlai
Site Admin
Posts:44
Joined:Tue Jan 15, 2013 3:16 pm
C program to reverse a given integer

Post by doctorlai » Thu Mar 20, 2014 5:48 pm

Code: Select all

#include <stdio.h>
 
int main() {
    int x;
    scanf("%d", &x);
    while (x != 0) {
        printf("%d", x % 10);
        x /= 10;
    }
    return 0;
}

Post Reply