Showing posts with label Factorial. Show all posts
Showing posts with label Factorial. Show all posts

TO FIND FACTORIAL OF A NUMBER USING C PROGRAM

How TO FIND FACTORIAL OF A NUMBER USING C PROGRAM.


#include<stdio.h>
int main(){
  int i=1,f=1,num;
  printf("\nEnter a number:");
  scanf("%d",&num);
  while(i<=num){
      f=f*i;
      i++;
  }
  printf("\nFactorial of %d is:%d",num,f);
  return 0;
}

C Program 0.1 + 0.2 != 0.3 Solved

How to write a C Program 0.1 + 0.2 != 0.3 Solved in C Programming Language ?


Solution For C Program :

C Program to Find Factorial Number

How to write a C Program to find the factorial of a number in C Programming Language ?

Solution of C Program: 

/*C Program to Find Factorial Number*/
#include<stdio.h>
void main()
{
int x, n, fact;
printf("\nEnter the value of n : ");
scanf("%d", &n);
x = 1;
fact = 1;
while(x <= n)
{
fact*=x;
x++;
}
printf("\nThe Factorial of a Number is : %d.", fact);
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable


Factorial Program In C Using Function

How to write a Factorial Program In C Using Function ?

Solution:

Factorial Program In C Using Function

#include<stdio.h>

long factorial(int);

main()
{
   int number;
   long fact = 1;

   printf("Enter a number to calculate it's factorial\n");
   scanf("%d",&number);

   printf("%d! = %ld\n", number, factorial(number));

   return 0;
}

long factorial(int n)
{
   int c;
   long result = 1;

   for( c = 1 ; c <= n ; c++ )
         result = result*c;

   return ( result );
}