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:

Sacred Thought

28 April 2024 Today I am going to explain verse 31 - 38 chapter two for you all. There is no opportunity better than a righteous war (सत्य औ...