Input
A positive integer, say n.
Output
All factorial numbers less than or equal to n.
#include<stdio.h>
int fac(int k)
{ if(k>1)
{
return k*fac(k-1);
}
if(k==1){return 1;}
}
int main(){
int f=0,n;
scanf("%d",&n);
for(int j=1; j<=n;j++)
{
f=fac(j);
if(f>n){break;}
printf("%d ", f);
}
}
int fac(int k)
{ if(k>1)
{
return k*fac(k-1);
}
if(k==1){return 1;}
}
int main(){
int f=0,n;
scanf("%d",&n);
for(int j=1; j<=n;j++)
{
f=fac(j);
if(f>n){break;}
printf("%d ", f);
}
}
Thanks
Happy Computing !
Output
ReplyDelete