bsc

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

root / semester_1 / assignment-secondary / assignment-s-01.c

assignment-s-01.c (720B)


      1 /* Write a program to compute the sum and product of digits of an integer using user
      2 defined functions. */
      3 
      4 #include <stdio.h>
      5 
      6 int sum_of_digits(int);
      7 int product_of_digits(int);
      8 
      9 int main()
     10 {
     11     int num;
     12     printf("Enter the number: ");
     13     scanf("%d", &num);
     14     printf("\nSum of digits of %d = %d", num, sum_of_digits(num));
     15     printf("\nProduct of digits of %d = %d", num, product_of_digits(num));
     16     return 0;
     17 }
     18 
     19 int sum_of_digits(int num)
     20 {
     21     int sum = 0;
     22     while (num > 0)
     23     {
     24         sum += num % 10;
     25         num /= 10;
     26     }
     27     return sum;
     28 }
     29 
     30 int product_of_digits(int num)
     31 {
     32     int product = 1;
     33     while (num > 0)
     34     {
     35         product *= num % 10;
     36         num /= 10;
     37     }
     38     return product;
     39 }
© 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