Write Program to input an integer. Find and print the sum of all even digit and product of odd digits.
Answers
Answered by
6
#include<stdio.h>
int main()
{
int a,eve = 0,od = 1,d,c;
printf("Enter a number : ");
scanf("%d",&a);
while(a > 0)
{
c = a % 10;
a = a / 10;
d = c % 2;
if(d! = 0)
od = od * c;
else
eve = eve + c;
}
printf("Sum of even numbers is %d\n", eve);
printf("Product of odd numbers is %d\n, odd);
}
return 0;
}
Output:
Enter an integer: 1237
The sum of even numbers = 2
The product of odd digits = 21.
Hope this helps!
int main()
{
int a,eve = 0,od = 1,d,c;
printf("Enter a number : ");
scanf("%d",&a);
while(a > 0)
{
c = a % 10;
a = a / 10;
d = c % 2;
if(d! = 0)
od = od * c;
else
eve = eve + c;
}
printf("Sum of even numbers is %d\n", eve);
printf("Product of odd numbers is %d\n, odd);
}
return 0;
}
Output:
Enter an integer: 1237
The sum of even numbers = 2
The product of odd digits = 21.
Hope this helps!
Similar questions
English,
7 months ago
India Languages,
7 months ago
Math,
1 year ago
Math,
1 year ago
Science,
1 year ago