-
Notifications
You must be signed in to change notification settings - Fork 7
/
reverse.c
32 lines (24 loc) · 1021 Bytes
/
reverse.c
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
// This is the program for finding the reverse of the number without using loop
/* Sample Input :
Enter the 3 digit number : 123
Sample Output :
The reverse of the number is : 321
*/
#include <stdio.h>
void main()
{
int num ,n,reverse=0; // variable declaration
printf("Enter the 3 digit number :");
scanf("%d",&num); // input number
n = num % 10; // separate the unit place and store it in variable 'n'
reverse = reverse*10 + n ; // add it to variable reverse after multiplying it by 10 so that it add at 10's place
num = num/10; // divide the number by 10 to convert it into 2 digit.
// For 3 digit number repeat this process for 3 times
n = num % 10;
reverse = reverse*10 + n ;
num = num/10;
n = num % 10;
reverse = reverse*10 + n ;
num = num/10;
printf("The reverse of the number is : %d",reverse); // output
}