how to reverse a number in c

Solutions on MaxInterview for how to reverse a number in c by the best coders in the world

showing results for - "how to reverse a number in c"
Hanae
03 Aug 2017
1#include <stdio.h>
2int main() {
3    int n, rev = 0, remainder;
4    printf("Enter an integer: ");
5    scanf("%d", &n);
6    while (n != 0) {
7        remainder = n % 10;
8        rev = rev * 10 + remainder;
9        n /= 10;
10    }
11    printf("Reversed number = %d", rev);
12    return 0;
13}
Janessa
03 Mar 2017
1#include <stdio.h>
2int main() {
3    int n, rev = 0, remainder;
4    printf("Enter an integer: ");
5    scanf("%d", &n);
6    while (n != 0) {
7        remainder = n % 10;
8        rev = rev * 10 + remainder;
9        n /= 10;
10    }
11    printf("Reversed number = %d", rev);
12    return 0;
13}
14
15
Gabriella
23 Jan 2017
1#include <stdio.h>
2int main() {
3    int n, rev = 0, remainder;
4    printf("Enter an integer: ");
5    scanf("%d", &n);
6    while (n != 0) {
7        remainder = n % 10;
8        rev = rev * 10 + remainder;
9        n /= 10;
10    }
11    printf("Reversed number = %d", rev);
12    return 0;
13}
14
similar questions
queries leading to this page
how to reverse a number in c