bsc

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

assignment-s-01.c (856B)


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