bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

pc-ip-02.c (696B)


      1 /*
      2  * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 05 Jan 2026
      3  * Repo: https://github.com/notamitgamer/bsc
      4  * License: MIT
      5  */
      6 
      7 /*
      8  * Question 2:
      9  * Write a program to reverse a non-negative integer using a function.
     10  */
     11 
     12 #include <stdio.h>
     13 
     14 int reverse(int);
     15 
     16 int main()
     17 {
     18     int num;
     19     printf("Enter the number: ");
     20     scanf("%d", &num);
     21     if (num < 0)
     22     {
     23         printf("\nOnly poitive integers are allowed.");
     24         return 1;
     25     }
     26     printf("\nReverse of input %d is : %d", num, reverse(num));
     27     return 0;
     28 }
     29 
     30 int reverse(int num)
     31 {
     32     int result = 0;
     33     while (num > 0)
     34     {
     35         result = (result * 10) + (num % 10);
     36         num /= 10;
     37     }
     38     return result;
     39 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror