C Program to Find and Print Product of all Digit of any Number

« C Tutorial C Examples »

Here we will learn about how to create a program in C that will ask from the user to enter any number (at run-time) as input and then calculate and print the product of all the digit of that given number. This program will only calculate the non-zero digit's product:

int main()
    int num, prod=1, rem;
    printf("Enter any number: ");
    scanf("%d", &num);
        rem = num%10;
            prod = prod*rem;
        num = num/10;
    printf("\nProduct of Digit = %d", prod);
    return 0;

As the program was written under Code::Blocks IDE, therefore after successful build and run, here is output you will see on your screen. Let's suppose that user has supplied the input number as 2345 and pressed ENTER key:

c program product of all digit

Let's take another sample run:

As you can see from the above sample run, 0 is skipped while multiplying the digits of the given number, as if we will take 0 along with non-zero digit, then the product will be 0.

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

C Online Test

« C Tutorial C Examples »

© Copyright 2021. All Rights Reserved.