forked from sarjus/C-Programing-KTU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactorial.c
45 lines (42 loc) · 1.31 KB
/
factorial.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/******************************************************
* File : factorial.c
* Description : C Program to find factorial of a number
* Author : Sarju S
* Version : 1.0
* Date : 07/05/2021
* ***************************************************/
#include<stdio.h>
int factorial(int);
int factorialRec(int);
int main(){
int number,factorialValue;
printf("\nEnter the number to find it's factorial:");
scanf("%d",&number);
factorialValue = factorial(number);
printf("\nFactorial Value of Number %d= %d",number,factorialValue);
printf("\nEnter the number to find it's factorial:");
scanf("%d",&number);
factorialValue = factorialRec(number);
printf("\nFactorial Value of Number %d= %d",number,factorialValue);
return 0;
}
//Function to find the factorial of the given number
//returns the result to main
int factorial(int number){
int i,factorialValue=1;
for(i=1;i<=number;i++){
factorialValue = factorialValue *i;
}
return factorialValue;
}
//Recursive Function to find the factorial of the given number
//returns the result to main
int factorialRec(int number){
//base condition
if(number==0){
return 1;
}
else{
return number * factorialRec(number-1);
}
}