188. C Program to Find the Sum of Even Digits and Product of Digits from the Given 6digits.
How does this program work?
- This program is used to find sum of even digits and product of odd digits from the given 6numbers.
Here is the code
int main(void)
{
//For a 6 digits numbers and find out the sum of even digits of that number and
//Multiplication of odd digits of that number
int n,n1;
printf("Enter a number:\n");
scanf("%d",&n);
n1 =n;
int sum = 0;
int product = 1;
//Compute sum of even digits
while (n != 0)
{
if(n%2==0)
sum = sum + n % 10;
n = n/10;
}
printf("Sum of even digits are: %d\n",sum);
//Compute product of odd digits
while(n1 != 0)
{
if(n1%2==1)
product = product*( n1 % 10);
n1 = n1/10;
}
printf("Product of odd digits are: %d\n",product);
return 0;
}