IP-02.c ​
Metadata ​
- Author — Amit Dutta (amitdutta4255@gmail.com)
- Last updated — 03 Jan 2026
- License — MIT
Problem Statement ​
Problem Statement
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 a non-negetive integer: ");
scanf("%d", &num);
if (num < 0)
{
printf("\nOnly non-negetive integers are allowed.");
return 1;
}
printf("\nReverse of the integer %d = %d", num, reverse(num));
return 0;
}
int reverse(int num)
{
int rev = 0;
while (num > 0)
{
rev = (rev * 10) + (num % 10);
num /= 10;
}
return rev;
}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