update
This commit is contained in:
11
DEV/DEV1.1_suite/TP_Recursivité/#Q1_Fibonacci.c#~
Normal file
11
DEV/DEV1.1_suite/TP_Recursivité/#Q1_Fibonacci.c#~
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int fibonacci(int nbMax, int resultat){
|
||||
if (result){
|
||||
return resultat
|
||||
}
|
||||
else{
|
||||
resultat+=fibonacci(nbMax-1, );
|
||||
}
|
||||
}
|
11
DEV/DEV1.1_suite/TP_Recursivité/Q1_Fibonacci.c
Normal file
11
DEV/DEV1.1_suite/TP_Recursivité/Q1_Fibonacci.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int fibonacci(int nbMax, int resultat){
|
||||
if (result){
|
||||
return resultat
|
||||
}
|
||||
else{
|
||||
resultat+=fibonacci(nbMax-1, );
|
||||
}
|
||||
}
|
21
DEV/DEV1.1_suite/TP_Recursivité/Q1_Fibonacci.c~
Normal file
21
DEV/DEV1.1_suite/TP_Recursivité/Q1_Fibonacci.c~
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int fibonacci(int rang){
|
||||
if (rang==0){
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
if (rang==1){
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
return fibonacci(rang-1) + fibonacci(rang-2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void){
|
||||
printf("%d\n",fibonacci(15));
|
||||
return 0;
|
||||
}
|
18
DEV/DEV1.1_suite/TP_Recursivité/Q3_tableau.c
Normal file
18
DEV/DEV1.1_suite/TP_Recursivité/Q3_tableau.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void printTab(double* tab, int taille){
|
||||
if (taille<=1){
|
||||
printf("%.2lf\n",*tab);
|
||||
}
|
||||
else {
|
||||
printf("%.2lf, ",*tab);
|
||||
printTab(tab+1,taille-1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void){
|
||||
double tab[]={8.36,666,3.141592,0,32};
|
||||
printTab(tab, 5);
|
||||
return 0;
|
||||
}
|
18
DEV/DEV1.1_suite/TP_Recursivité/Q3_tableau.c~
Normal file
18
DEV/DEV1.1_suite/TP_Recursivité/Q3_tableau.c~
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void printTab(double* tab){
|
||||
if (*tab){
|
||||
printf("%.2lf, ",*tab);
|
||||
printTab(tab+1);
|
||||
}
|
||||
else{
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main(void){
|
||||
double tab[]={8.36,666,3.141592,32};
|
||||
printTab(tab);
|
||||
return 0;
|
||||
}
|
67
DEV/DEV1.1_suite/TP_Recursivité/Q4_Hanoi.c
Normal file
67
DEV/DEV1.1_suite/TP_Recursivité/Q4_Hanoi.c
Normal file
@@ -0,0 +1,67 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void affichePyramide(int* pyramides, int nbPlateau){
|
||||
int numEtage, numPyramide, espace, numChar;
|
||||
for (numEtage=0; numEtage<nbPlateau; numEtage++){
|
||||
for (numPyramide=0; numPyramide<3; numPyramide++){
|
||||
espace = nbPlateau*2-1-pyramides[numPyramide*3 +numEtage];
|
||||
if (pyramides[numPyramide*3 +numEtage]==0){
|
||||
printf(" ");
|
||||
}
|
||||
for (numChar=0; numChar<espace; numChar++){
|
||||
printf(" ");
|
||||
}
|
||||
for (numChar=0; numChar<pyramides[numPyramide*3+numEtage]*2-1; numChar++){
|
||||
printf("*");
|
||||
}
|
||||
for (numChar=0; numChar<espace; numChar++){
|
||||
printf(" ");
|
||||
}
|
||||
printf(" ");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int* initialisation(int nbPlateau){
|
||||
int* pyramides = (int*) malloc(3*nbPlateau*sizeof(int));
|
||||
int numPlateau;
|
||||
for (numPlateau=nbPlateau-1; numPlateau>=0; numPlateau--){
|
||||
pyramides[numPlateau] = numPlateau*2-1;
|
||||
}
|
||||
for (numPlateau=nbPlateau*3-1; numPlateau>=nbPlateau; numPlateau--){
|
||||
pyramides[numPlateau] = 0;
|
||||
}
|
||||
return pyramides;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv){
|
||||
int nbPlateau;
|
||||
int* pyramides=NULL;
|
||||
int* test=NULL;
|
||||
if (argc<2){
|
||||
printf("Saisissez un nombres de plateau (entre 1 et 15)\n");
|
||||
}
|
||||
else{
|
||||
nbPlateau = (int) strtod(argv[1],NULL);
|
||||
if (nbPlateau<1){
|
||||
nbPlateau=1;
|
||||
}
|
||||
if (nbPlateau>15){
|
||||
nbPlateau=15;
|
||||
}
|
||||
printf("%d\n",nbPlateau);
|
||||
pyramides = initialisation(nbPlateau);
|
||||
test=pyramides;
|
||||
while (*test){
|
||||
printf("%d ",*test);
|
||||
test+=1;
|
||||
}
|
||||
printf("\n");
|
||||
affichePyramide(pyramides, nbPlateau);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
0
DEV/DEV1.1_suite/TP_Recursivité/Q4_Hanoi.c~
Normal file
0
DEV/DEV1.1_suite/TP_Recursivité/Q4_Hanoi.c~
Normal file
BIN
DEV/DEV1.1_suite/TP_Recursivité/exe
Executable file
BIN
DEV/DEV1.1_suite/TP_Recursivité/exe
Executable file
Binary file not shown.
Reference in New Issue
Block a user