Week-1(Assignment - 3)
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
Constraint:
1<=N<=999999
Input: A single number
Output: The value
Example 1:
Input: 657
Output: 210
Example 2:
Input: 7
Output: 7
#include<stdio.h>
int main()
{
int n,ans=1;
scanf("%d",&n);
if(n==0)
{
ans = 0;
printf("\n%d",ans);
return 0;
}
while(n>0)
{
ans = ans * (n%10);
n/=10;
}
printf("\%d",ans);
return 0;
}
No comments:
Post a Comment