In this tutorial you will learn about the C program, to calculate Product of Digits of a Number and its application with practical example.
C program to calculate Product of Digits of a Number
In this tutorial, we will learn to create a C program that will calculate the Product of Digits of a Number using C programming.
Before starting with this tutorial, we assume that you are the 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.
- Conditional Statements in C programming.
- Arithmetic operations in C Programming.
1. Declaring the required variables for the program.
2. Taking the input amount from the user.
3. Using the <strong>mathematical expressions </strong>to find the number of notes.
4. Printing the notes to the user.
5. End the Program.
Calculate the Product of Digits of a number:-
In this program, we will take the input number from the user. Then we will pass that number to a while loop to break it down. Then we will use arithmetic statements to find the digits from that number. After that, we will find the product of the digits. At last, we will print the product of the digits to the user.
With the help of the below program, we can find a product of the digits in a number.
/* C program, to calculate Product of Digits of a Number */
#include<stdio.h> // include stdio.h library
//declaring the required variables for the program.
int no, rem, prod = 1;
//Amount = it will hold the input amount from the user.
//i = it will hold the integer value for the loop.
//flag = it will hold the temporary value.
// Taking the Input number from user
printf("Enter a number: ");
//Scanning the input number from the user.
//Calculating the product of the digits
while(no != 0)
rem = no % 10; // get the right-most digit
prod *= rem; // calculate product of digits
no /= 10; // remove the right-most digit
//Printing the product of the digits of the number.
return 0; // return 0 to operating system
In the above program, we have first initialized the required variable.
- no = it will hold the integer value for the input.
- i = it will hold the integer value for the controlling of the loop.
- rem = it will hold the integer value for the reminder.
- prod = it will hold the integer value for the product.
Taking the input amount from the user.
Converting the notes for the amount.