Thursday, 11 February 2016

C program that takes a positive number N and produces an output that is the product of its digits

Write a C program that takes a positive number N and produces an output that is the product of its digits.

Explanation:

Take number 657.

Answer expected : 6 * 5 * 7 = 210

Solution
#include<stdio.h> int main() { int a, test, c, product=1; scanf("%d", &a); test=a; while(a!=0) { c=a%10; product=product*c; a=a/10; }; printf("%d", product); return 0; }

No comments:

Post a Comment