59 lines
967 B
C
59 lines
967 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int recfact(int x){
|
|
int y = 1;
|
|
if (x==1){
|
|
return y;
|
|
} else {
|
|
return y *= x *recfact(x-1);
|
|
}
|
|
}
|
|
|
|
int recfor(int x){
|
|
int gaga = 1;
|
|
for (int i = 1; i < x;) {
|
|
gaga *= i++;
|
|
}
|
|
return gaga;
|
|
}
|
|
|
|
/*
|
|
* i = 1, gaga = 1*2
|
|
* i = 2, gaga = 1*2*3 = 6
|
|
* i = 3, 1*2*3*4 = 24
|
|
*
|
|
* wrong loop time condition
|
|
* wrong calculation
|
|
*
|
|
* ---
|
|
*
|
|
* recursion
|
|
*
|
|
* forgot to assign, forgot a number (multiplied by 0)
|
|
* misunderstood calculation
|
|
|
|
wel exploren, maar wel naar een doel.
|
|
kijken naar auxililiaries.
|
|
curiosity wss, leren vragen. leren wat ik niet heb, weten wat ik niet weet.
|
|
|
|
zoektocht heeft wat sturing nodig.
|
|
|
|
hoe ik mijn probeer stel/vind
|
|
het probleem onderzoeken
|
|
|
|
limiteer de pogingen
|
|
|
|
|
|
hardware / networking
|
|
* * */
|
|
|
|
int main () {
|
|
int i = 6; // we can not handle negative numbers
|
|
|
|
printf("%d\n", recfor(i));
|
|
printf("%d\n", recfact(i));
|
|
|
|
return 0;
|
|
}
|