C Program to accept a number and find factorial of given number

Program 1: Factorial program in c using for loop

#include<stdio.h>
#include<conio.h>
int main(){
  int i,f=1,num;
  printf("Enter a number: ");
  scanf("%d",&num);
  for(i=1;i<=num;i++)
      f=f*i;
 printf("Factorial of %d is: %d",num,f);
  return 0;
 getch();
}
Output:
Program 2: Factorial program in c using function

#include<stdio.h>
#include<conio.h>
int findFactorial(int);
int main(){
 int i,factorial,num;
 printf("Enter a number: ");
  scanf("%d",&num);
  factorial = findFactorial(num);
  printf("Factorial of %d is: %d",num,factorial);
  return 0;
getch();
}
 int findFactorial(int num){
    int i,f=1;
   for(i=1;i<=num;i++)
      f=f*i;
    return f;
}


Output:

Program 3: Factorial series in c
#include<stdio.h>
int main(){
  long f=1;
  int i,num,min,max;

  printf("Enter the minimum range: ");
  scanf("%d",&min);

  printf("Enter the maximum range: ");
  scanf("%d",&max);

  printf("Factorial series in given range: ");
  for(num=min;num<=max;num++){
    f=1;

    for(i=1;i<=num;i++)
      f=f*i;

    printf("%ld ",f);
  }

  return 0;

}

Output:


No comments:

Post a Comment

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...