Sunday, February 25, 2018

C program: To list all the factorial numbers less than or equal to an input number n.

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);
       
    }


}

Thanks
Happy Computing !

1 comment:

How can I run a C++ program directly from Windows?

How-can-I-run-a-C-program-directly-from-Windows