PROGRAM TO FIND SUM AND PRODUCT OF ALL DIGITS OF A NUMBER
/* PROGRAM TO FIND SUM AND PRODUCT OF ALL DIGITS OF A NUMBER */
#include <stdio.h>
intmain()
{
int n;
int dig,sum,pro;
printf("\nEnter an integer number :");
scanf("%d",&n);
/*Calculating Sum and Product*/
sum=0;
pro=1;
while(n>0)
{
dig=n%10;/*get digit*/
sum+=dig;
pro*=dig;
n=n/10;
}
printf("\nSUM of all Digits is : %d",sum);
printf("\nPRODUCT of all digits: %d",pro);
return0;
}
Output :-
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment