Q:

C Program To Find Factorial of a Number

belongs to collection: Basic C Programming Examples

0

you have to make this program in the following way:

  1. C Program To Find Factorial of a Number Using For Loop
  2. C Program To Find Factorial of a Number Using While Loop
  3. C Program To Find Factorial of a Number Using Do While Loop

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C Program To Find Factorial of a Number Using For Loop

Algorithm

  • Program Start
  • Declare Variables
  • Input a number from the user
  • Assign Value in the variable
  • Loop start to find factorial
  • Display factorial of a number
  • Program End

Program

//C Program To Find Factorial of a Number Using For Loop

#include<stdio.h>
void main()
{
  int i,fact=1,n;

  printf("Enter a number: ");
  scanf("%d",&n);

  for(i=1;i<=n;i++)
      fact=fact*i;

  printf("Factorial of %d is: %d",n,fact);

}

Output

Enter a number: 3
Factorial of 3 is: 6

C Program To Find Factorial of a Number Using While Loop

Program

//C Program To Find Factorial of a Number Using While Loop

#include<stdio.h>
void main()
{
  int i=1 ,fact=1,n;

  printf("Enter a number: ");
  scanf("%d",&n);

  while(i<=n)
  {
      fact=fact*i;
      i++;
  }
  printf("Factorial of %d is: %d",n,fact);

}

Output

Enter a number: 5
Factorial of 5 is: 120

C Program To Find The Factorial of a Number Using Do While Loop

Program

//C Program To Find Factorial of a Number Using Do While Loop 

#include<stdio.h>
void main()
{
  int i=1 ,fact=1,n;

  printf("Enter a number: ");
  scanf("%d",&n);

  do
  {
      fact=fact*i;
      i++;
  } while(i<=n);
  printf("Factorial of %d is: %d",n,fact);

}

Output

Enter a number: 10
Factorial of 10 is: 3628800

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Basic C Programming Examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program To Check Vowel or Consonant... >>
<< C Program To Print Multiplication Table (5 Differe...