pc-ip-02.c ​
Metadata ​
- Author — Amit Dutta (amitdutta4255@gmail.com)
- Last updated — 05 Jan 2026
- License — MIT
Problem Statement ​
Problem Statement
Question 2: Write a program to reverse a non-negative integer using a function.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
int reverse(int);
int main()
{
int num;
printf("Enter the number: ");
scanf("%d", &num);
if (num < 0)
{
printf("\nOnly poitive integers are allowed.");
return 1;
}
printf("\nReverse of input %d is : %d", num, reverse(num));
return 0;
}
int reverse(int num)
{
int result = 0;
while (num > 0)
{
result = (result * 10) + (num % 10);
num /= 10;
}
return result;
}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
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