Q:

Factorial of a Number In C Using Function

belongs to collection: Function Programs in C

0

Factorial of a Number In C Using Function

All Answers

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

Factorial of a Number In C Using Function

Algorithm

  • Program Start
  • Declaring Variable
  • Input Number From the user
  • Calling Function
  • Loop start
  • return result
  • function End
  • Display Result Through Printf Function
  • Program End

Program

//C program to find Factorial of a Number Using Function

#include<stdio.h>
int factorial(int num)
{  int i = 1, fact = 1;
   do
  {
      fact=fact*i;
      i++;
  } while(i<=num);

  return (fact);
}

void main()
{
  int n;

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

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

}

Output

Enter a number: 7
Factorial of 7 is: 5040

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

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program To Find Prime Number Using Function... >>