pc-ip-01.c (898B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 05 Jan 2026 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* 9 * Question 1: 10 * Write a program to compute the sum and product of digits of an integer using user-defined functions. 11 */ 12 13 #include <stdio.h> 14 15 int sum(int); 16 int product(int); 17 18 int main() 19 { 20 int num; 21 printf("Enter the number: "); 22 scanf("%d", &num); 23 printf("\nSum of digit: %d", sum(num)); 24 printf("\nProduct of digit: %d", product(num)); 25 return 0; 26 } 27 28 int sum(int num) 29 { 30 int result = 0; 31 while (num > 0) 32 { 33 result += num % 10; 34 num /= 10; 35 } 36 return result; 37 } 38 39 int product(int num) 40 { 41 int result = 1; 42 if (num == 0) 43 { 44 return 0; 45 } 46 while (num > 0) 47 { 48 result *= num % 10; 49 num /= 10; 50 } 51 return result; 52 }