bsc

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

root / semester_1 / letusc / luc004.c

luc004.c (652B)


      1 /* If a five digit number is input through the keyboard,
      2 write a program to calculate the sum of it's digit.
      3 (Hint : Use the modulus operator %) */
      4 /* Let Us C; Page - 37; Chap- 2; QNo.: G(a) */
      5 
      6 #include <stdio.h>
      7 int main()
      8 {
      9     int inp, result = 0, i, temp;
     10     printf("Enter a five digit number : ");
     11     scanf("%d", &inp);
     12     if (inp < 10000 || inp > 99999)
     13     {
     14         printf("\nPlease enter a valid five digit number.");
     15         return 1;
     16     }
     17     temp = inp;
     18     for (i = 1; i <= 5; i++)
     19     {
     20         result = result + (inp % 10);
     21         inp = inp / 10;
     22     }
     23     printf("\nSum of the digit '%d' is : %d", temp, result);
     24     return 0;
     25 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror