blob: 4432f6a4047fc92aa0aa3a0dfcf212833ddf0234 (
plain)
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
|
#include <iostream>
#include <cmath>
#include <stdlib.h> /* atoi */
#include "fonctionsMysterieuses.h"
int apuissanceb(int a, int b) {
// renvoie a puissance b
if (b==0) return 1;
if (b % 2 == 0) return apuissanceb(a * a, b / 2);
return a * apuissanceb(a,b-1);}
int main(int argv, char** argc){
int numeroFonction = atoi(argc[1]),
n = atoi(argc[2]),
v;
for (int i = 0; i < n; i+=1){
switch (numeroFonction) {
case 1 : v=f1(i); break;
case 2 : v=f2(i); break;
case 3 : v=f3(i); break;
case 4 : v=f4(i); break;
case 5 : v=f5(i); break;
case 6 : v=f6(i); break;
}
std::cout<<"f"<<numeroFonction<<"("<<i<<") renvoie "<<v<<" "<< f5(i)/pow(2,i)<<std::endl;
}
return 0;
}
/*
ordre de compilation : g++ SolutionsFonctionMysterieuses.cpp fonctionsMysterieuses.o -o test
Ordre d'ex�cution : ./test 1 2
*/
/*f1(x)= 3 * sqrt(x)
f2(x)= 1/10* x^5
f3(x)= 1/2 * n^2
f4(x) = 2 * ln(x)
f5(x)= 10* 2^n
f6(x)=20 * 3^n
*/
|