external_1.c (540B)
1 // 1. Write a program to print the sum and product of digits of an integer. 2 3 #include<stdio.h> 4 5 int sum(int); 6 int product(int); 7 8 int main() { 9 int num; 10 printf("Enter a positive integer: "); 11 scanf("%d", &num); 12 printf("\nSum of the integer is %d", sum(num)); 13 printf("\nProduct of the integer is %d", product(num)); 14 return 0; 15 } 16 17 int sum(int num) { 18 int s = 0; 19 while (num != 0) { 20 s += num % 10; 21 num = num / 10; 22 } 23 return s; 24 } 25 26 int product(int num) { 27 int pro = 1; 28 while(num != 0) { 29 pro *= num % 10; 30 num /= 10; 31 } 32 return pro; 33 }