Problem statement:
Given a number N. Find the smallest number where the product of the digits is equal to N.
E.g.:
if N is 8 then output should be 18 because 1*8=8 and not 24 (2*4) or 42 (4*2)
Input:
8
Output:
18
CODE:
Given a number N. Find the smallest number where the product of the digits is equal to N.
E.g.:
if N is 8 then output should be 18 because 1*8=8 and not 24 (2*4) or 42 (4*2)
Input:
8
Output:
18
CODE:
#include <stdio.h>
int main()
{
int
n,i,j,arr[100],k=0;
scanf("%d",&n);
if(n<10)
printf("%d",10+n);
else
{
for(i=9;i>1;i--)
{
while(n%i==0)
{
n=n/i;
arr[k]=i;
k++;
}
}
if(n>10)
printf("No Such Number");
for(j=k-1;j>=0;j--)
printf("%d",arr[j]);
}
return 0;
}
OUTPUT:
No comments:
Post a Comment