Monday 1 February 2016

NPTEL(Week - 1)



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

How to install google-chrome in redhat without redhat subscription

Install google-chrome in redhat  Download the .rpm file of chrome https://www.google.com/chrome/thank-you.html?installdataindex=empty&st...