bsc

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

luc004.c (788B)


      1 /*
      2  * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 12 Dec 2025
      3  * Repo: https://github.com/notamitgamer/bsc
      4  * License: MIT
      5  */
      6 
      7 /* If a five digit number is input through the keyboard,
      8 write a program to calculate the sum of it's digit.
      9 (Hint : Use the modulus operator %) */
     10 /* Let Us C; Page - 37; Chap- 2; QNo.: G(a) */
     11 
     12 #include <stdio.h>
     13 int main()
     14 {
     15     int inp, result = 0, i, temp;
     16     printf("Enter a five digit number : ");
     17     scanf("%d", &inp);
     18     if (inp < 10000 || inp > 99999)
     19     {
     20         printf("\nPlease enter a valid five digit number.");
     21         return 1;
     22     }
     23     temp = inp;
     24     for (i = 1; i <= 5; i++)
     25     {
     26         result = result + (inp % 10);
     27         inp = inp / 10;
     28     }
     29     printf("\nSum of the digit '%d' is : %d", temp, result);
     30     return 0;
     31 }
© 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