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:

Henry's law constant for CO 2 ​ in water is 1.67×10 ∘ Pa at 298 K . Calculate the quantity of CO 2 ​ in 500 mL , of soda water when packed under 2.5 atm CO 2 ​ pressure at 298 K .

  Explanation To calculate the amount of CO 2 ​ dissolved, we use Henry's Law: P = k H ​ × x _ C O 2 ​ where:\ P = partial pressure of...