Q7) Complete the function int find_factorial(int k) to find the factorial of the positive number k.
The factorial of a positive integer k
, denoted by k!
, is the product of all positive integers less than or equal to k
.
k!=k×(k−1)×⋯×1.
Input
---------
The first line of input is a positive integer N.
The next line contains N positive integers ki
for i=1 to N.
.
Output
---------
For each ki
given as input, print factorial of ki
.
Note
---------
The code stub given takes care of reading the input, passing it over to the function find_factorial and printing the value (factorial of k) returned by the function. You have to just complete the function find_factorial, which takes a single positive integer k
as input and returns k!
.
#include
int find_factorial(int k) {
int i, factorial = 1;
for (i = 1; i <= k; i++) {
factorial = factorial * i;
}
return factorial;
}
int main() {
int N, i, k;
scanf("%d", &N);
for (i = 0; i < N; i++) {
scanf("%d", &k);
printf("%d\n", find_factorial(k));
}
return 0;
}