Calculate the product of digits of a number with C.
#include <stdio.h>
int main()
{
int number;
long long product = 1ll;
printf("Enter any number to calculate product of digit: ");
scanf("%d", &number);
product = (number == 0 ? 0 : 1ll);
while (number != 0)
{
product = product * (number % 10);
/* Remove the last digit from n */
number = number / 10;
}
printf("Product of digits = %lld", product);
return 0;
}
output:-
Enter any number to calculate product of digit : 45678
Product of digits = 6720
0 Comments