58. C Program To find the Sum and Product of Individual Digits of a Given Number.
How does this program work?
- This Program is used to find the sum and product of a given number.
Here is the code
#include <stdio.h>
int main(void)
{
int n,r,t,sum=0,product=1;
printf("Enter a number\n");
scanf("%d",&n);
t=n;
while(t!=0)
{
r=t%10;
sum=sum+r;
product=product*r;
t=t/10;
}
printf("sum of the digits=%d\n",sum);
printf("Product of the digits=%d\n",product);
return 0;
}