-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmbeddedSystemDesign_HW_week5.2.c
48 lines (40 loc) · 1.08 KB
/
EmbeddedSystemDesign_HW_week5.2.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
46
47
48
/*
Problem: Make a function that calculates the factorial of given integer number and returns the result. The number n is passed as a
parameter. Range for value for n = 0 - 12.
For example:
Test | Result
-------------------------------------------
int n=12; | 479001600
printf("%ld",factorial(n)); |
-------------------------------------------
int n=0; | 1
printf("%ld",factorial(n)); |
*/
#include <stdio.h>
#include <math.h>
#include <string.h>
//function prototype(s)
long int factorial(int n);
/*---------------------------------------------------------------------------------------------------------------------------------*/
//main function
int main(void)
{
//declair vars
int n=12;
//functions
printf("%ld\n",factorial(n));
return 0;
}//end main
/*---------------------------------------------------------------------------------------------------------------------------------*/
//fuction(s) declaration
long int factorial(int n)
{
//declair vars
long int result=1;
//functions
for(int i=0; i<n; i++)
{
result = result*(i+1);
}
return result;
}//end factorial