Coding Practice

Write a C program to calculate product of digits of a number

Calculate product of digits of a number
Sample Output
Calculate product of digits of a number.

Number: 12345

Product: 120
Source Code
#include<stdio.h>

int main()
{
    int number, digit, product = 1;

    printf("Calculate product of digits of a number.\n\nNumber: ");
    scanf("%d", &number);

    while(number != 0)
    {
        digit = (number % 10);
        product = product * digit;
        number = (number / 10);
    }
    printf("\nProduct: %d\n\n", product);
    return 0;
}
Sample Output
Calculate product of digits of a number.

Number: 59

Product: 45

No comments:

Post a Comment

Change Theme
X