bsc

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

IP-02.c (685B)


      1 /*
      2  * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 03 Jan 2026
      3  * Repo: https://github.com/notamitgamer/bsc
      4  * License: MIT
      5  */
      6 
      7 /* Write a program to reverse a non-negative integer using a function. */
      8 
      9 #include <stdio.h>
     10 
     11 int reverse(int);
     12 
     13 int main()
     14 {
     15     int num;
     16     printf("Enter a non-negetive integer: ");
     17     scanf("%d", &num);
     18     if (num < 0)
     19     {
     20         printf("\nOnly non-negetive integers are allowed.");
     21         return 1;
     22     }
     23     printf("\nReverse of the integer %d = %d", num, reverse(num));
     24     return 0;
     25 }
     26 
     27 int reverse(int num)
     28 {
     29     int rev = 0;
     30     while (num > 0)
     31     {
     32         rev = (rev * 10) + (num % 10);
     33         num /= 10;
     34     }
     35     return rev;
     36 }
© 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