Ajout des travaux effectuer
This commit is contained in:
20
23DEV1.1/TPS1/TP2/22-Recursive/Curiosity.c
Normal file
20
23DEV1.1/TPS1/TP2/22-Recursive/Curiosity.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
int f(int n) {
|
||||
if (n>100)
|
||||
return n-10;
|
||||
else
|
||||
return f(f(n+11));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
srand(time(NULL));
|
||||
int final;
|
||||
int alea = rand()%1000+1000;
|
||||
final = f(alea);
|
||||
printf("%d", final);
|
||||
return 0;
|
||||
}
|
||||
51
23DEV1.1/TPS1/TP2/22-Recursive/Fibonacci.c
Normal file
51
23DEV1.1/TPS1/TP2/22-Recursive/Fibonacci.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int Fibonacci(int n)
|
||||
{
|
||||
if(n==0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(n==1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if(n>=2)
|
||||
{
|
||||
n = Fibonacci(n-2)+Fibonacci(n-1);
|
||||
return n;
|
||||
}
|
||||
Fibonacci(n+1);
|
||||
}
|
||||
int afficheFibo(int m)
|
||||
{
|
||||
if(m!=0)
|
||||
{
|
||||
if(m==1)
|
||||
{
|
||||
printf("u%d = %d",m,Fibonacci(1));
|
||||
}
|
||||
if(m>=2)
|
||||
{
|
||||
printf("u%d = %d",m,Fibonacci(m));
|
||||
}
|
||||
afficheFibo(m-1);
|
||||
}
|
||||
if(m==0)
|
||||
{
|
||||
printf("u%d = %d\n",m,Fibonacci(0));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
int m = 15;
|
||||
afficheFibo(m);
|
||||
//int n;
|
||||
//printf("choisissez un nombre : ");
|
||||
//scanf("%d",&n);
|
||||
//printf("u%d = %d",n,Fibonacci(n));
|
||||
return 0;
|
||||
}
|
||||
23
23DEV1.1/TPS1/TP2/22-Recursive/Tableau.c
Normal file
23
23DEV1.1/TPS1/TP2/22-Recursive/Tableau.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
void tableau(double tab[5], int d)
|
||||
{
|
||||
int num = d;
|
||||
printf("%lf", tab[num]);
|
||||
if(num<4){
|
||||
printf(", ");
|
||||
tableau(tab, num+1);
|
||||
}else{
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
double tab[5] = {1.25, 47.80, 77.01, 54.23, 895.14};
|
||||
tableau(tab, 0);
|
||||
return 0;
|
||||
}
|
||||
BIN
23DEV1.1/TPS1/TP2/22-Recursive/Triangle
Executable file
BIN
23DEV1.1/TPS1/TP2/22-Recursive/Triangle
Executable file
Binary file not shown.
28
23DEV1.1/TPS1/TP2/22-Recursive/Triangle.c
Normal file
28
23DEV1.1/TPS1/TP2/22-Recursive/Triangle.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <graph.h>
|
||||
|
||||
void triangle(int x1, int y1, int x2, int y2,int x3, int y3, int n){
|
||||
if(n == 0){
|
||||
DessinerSegment(x1, y1, x2, y2);
|
||||
DessinerSegment(x2, y2, x3, y3);
|
||||
DessinerSegment(x3, y3, x1, y1);
|
||||
}else{
|
||||
triangle(x1, y1, (x2+x1)/2, y2, (x1+x3)/2, (y2+y3)/2, n-1);
|
||||
triangle((x1+x2)/2, y1, x2, y2, (x2+x3)/2, (y2+y3)/2, n-1);
|
||||
triangle((x1+x3)/2, (y1+y3)/2, (x2+x3)/2, (y2+y3)/2, x3, y3, n-1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int n = 0;
|
||||
printf("Entrez un entier positif : ");
|
||||
scanf("%d", &n);
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(10,10,1000,800);
|
||||
triangle(10, 790, 990, 790, 500, 10, n);
|
||||
Touche();
|
||||
FermerGraphique();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
BIN
23DEV1.1/TPS1/TP2/22-Recursive/a.out
Executable file
BIN
23DEV1.1/TPS1/TP2/22-Recursive/a.out
Executable file
Binary file not shown.
17
23DEV1.1/TPS1/TP2/22-Recursive/phrases.c
Normal file
17
23DEV1.1/TPS1/TP2/22-Recursive/phrases.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void exemple(unsigned n) {
|
||||
if (n != 0) {
|
||||
putchar('>');//à la fin
|
||||
exemple(n-1);
|
||||
putchar('<');//au début
|
||||
} else
|
||||
putchar('O');
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
exemple(100);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user