C Program to Print Sum of Even & Product of Odd Digit

In this tutorial, we will learn about how to create a program in C that will ask from user to enter any number as input to find and print sum of even digit and product of odd digit present in that given number.

The question is, write a program in C to print the sum of even digit and product of odd digit of any given Number from user at run-time. Here is the program:

int main()
    int num, evenSum=0, oddProd=1, rem, temp;
    printf("Enter any number: ");
    scanf("%d", &num);
        rem = num%10;
            evenSum = evenSum + rem;
            oddProd = oddProd * rem;
        num = num/10;
    printf("\nSum of Even Digit = %d", evenSum);
    printf("\nProduct of Odd Digit = %d", oddProd);
    return 0;

As the above program was written under Code::Blocks IDE, therefore after successful build and run, here is the sample run:

c program print sum of even position

Supply any number say 234879 and press ENTER key to see the sum of even digit (that is 2, 4, and 8) and the product of odd digit (that is 3, 7, and 9). As the digit 2, 4 and 8 are the three even numbers and 3, 7 and 9 are the three odd numbers. Therefore the program will calculate the sum of even and product of odd digit (number). Here is the second snapshot of the sample run:

print product of odd digits c

Here are some of the main steps used in above program:

C Online Test

« Previous Program Next Program »

© Copyright 2021. All Rights Reserved.