In this tutorial you will learn about the C Program to Print Sum of Even & Product of Odd Digit and its application with practical example.
C Program to Print Sum of Even & Product of Odd Digit
In this tutorial, we will learn to create a C program that will Print Sum of Even & Product of Odd Digit using C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- While loop in C programming.
- Arithmetic operations in C Programming.
Program to Print Sum of Even & Product of Odd Digit
In c programming, it is possible to take numerical input from the user and Print Sum of Even & Product of Odd Digit with the help of a very small amount of code. The C language has many types of header libraries which has supported function in them with the help of these files the programming is easy.
With the help of this program, we can Print Sum of Even & Product of Odd Digit.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the variables for the program. 2. Taking the input number from the user. 3. Calculating the sum of even numbers. 4. Calculating the product of the odd numbers. 5. Printing the result numbers. |
Program to Print Sum of Even & Product of Odd Digit:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#include<stdio.h> int main() { //declaring the variable for the program int no, evenSum=0, oddProd=1, rem, temp; //showing the message for the input printf("Enter any number: "); //scanning the number scanf("%d", &no); //using while loop to sort even odd numbers and calculating //the sum nad products of digits of a number while(no>0) { rem = no%10; if(rem%2==0) evenSum = evenSum + rem; else oddProd = oddProd * rem; no = no/10; } //Printing the output of the program printf("\nSum of Even Digit = %d", evenSum); printf("\nProduct of Odd Digit = %d", oddProd); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- evenSum = it will hold the integer value for the sum of numbers.
- oddProd = it will hold the integer value for the product of the numbers.
- temp = it will hold the temporary integer value.
- rem = it will hold the integer value of the remainder.
- no = it will hold the integer value of the input.
Input number from the user.
Program Logic Code.
Printing output for sum and the product.