-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp-6-16.c
More file actions
44 lines (36 loc) · 863 Bytes
/
exp-6-16.c
File metadata and controls
44 lines (36 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*************************************************************************
> File Name: exp-6-16.c
> Author: xiaoxiaoh
> Mail: xiaoxxhao@gmail.com
> Created Time: Fri Jul 7 14:35:59 2017
************************************************************************/
/*
* Write a C program to enter any number and print its reverse.
*
* Example
*
* Input
* Input number: 1234
*
* Output
* Reverse of 1234 = 4321
*
*/
#include <stdio.h>
int main()
{
int num, reverse=0;
//Read a number from user
printf("Enter a number: ");
scanf("%d", &num);
printf("The original number is %d, the reverse number of it is ", num);
//repeat the till number becomes 0
while(num != 0)
{
// multiple reverse by 10 and adds the last digit to it
reverse = (reverse * 10) + (num % 10);
num /= 10;
}
printf("%d\n", reverse);
return 0;
}