write a program to print the sum of product of an integer in C
//write a program to print the sum of product of an integer
#include <stdio.h>
int main()
{
int n, digit, sum, product;
printf("\nEnter an integer number :");
scanf("%d", &n);
/* Calculating sum and product */
sum=0;
product=1;
while(n>0)
{
digit=n%10; /*get digit*/
sum+=digit;
product*=digit;
n=n/10;
}
printf("\nSum of all digit is: %d", sum);
printf("\nProduct of all digit: %d", product);
return 0;
}
Comments
Post a Comment