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:

Is the number of all INTO functions from the set {1, 2, 3, ..... n} to itself equal to all number of MANY to ONE fuctions?

Yes,  t he number of all into functions from the set {1, 2, 3, .... n} to itself is exactly equal to the number of many-to-one functions ...