Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
30
Task/Multifactorial/C/multifactorial.c
Normal file
30
Task/Multifactorial/C/multifactorial.c
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* Include statements and constant definitions */
|
||||
#include <stdio.h>
|
||||
#define HIGHEST_DEGREE 5
|
||||
#define LARGEST_NUMBER 10
|
||||
|
||||
/* Recursive implementation of multifactorial function */
|
||||
int multifact(int n, int deg){
|
||||
return n <= deg ? n : n * multifact(n - deg, deg);
|
||||
}
|
||||
|
||||
/* Iterative implementation of multifactorial function */
|
||||
int multifact_i(int n, int deg){
|
||||
int result = n;
|
||||
while (n >= deg + 1){
|
||||
result *= (n - deg);
|
||||
n -= deg;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Test function to print out multifactorials */
|
||||
int main(void){
|
||||
int i, j;
|
||||
for (i = 1; i <= HIGHEST_DEGREE; i++){
|
||||
printf("\nDegree %d: ", i);
|
||||
for (j = 1; j <= LARGEST_NUMBER; j++){
|
||||
printf("%d ", multifact(j, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue