From f2ccb1e1bd93d882d9f61d29e35498ffe74128ca Mon Sep 17 00:00:00 2001 From: Mysaa Date: Wed, 13 Oct 2021 01:13:27 +0200 Subject: [PATCH] Fiche C6 --- C6.1.c | 28 ++++++++++ C6.2.c | 18 ++++++ C6.6.c | 43 +++++++++++++++ C6.7.c | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ C6.md | 67 ++++++++++++++++++++++ 5 files changed, 328 insertions(+) create mode 100644 C6.1.c create mode 100644 C6.2.c create mode 100644 C6.6.c create mode 100644 C6.7.c create mode 100644 C6.md diff --git a/C6.1.c b/C6.1.c new file mode 100644 index 0000000..efe78b9 --- /dev/null +++ b/C6.1.c @@ -0,0 +1,28 @@ +#include + +#define N 100 + +int divisible(int n, int q){ + return n%q==0; +} + +int premier(int n){ + if(n<2)return 0; + for(int k=2;k*k<=n;k++){ + if(divisible(n,k)) + return 0; + } + return 1; +} + +int main() { + int n; + do{ + printf("Quel nombre ? "); + scanf("%d",&n); + }while(0>=n || n>=1000); + + for(int k=2;k<=n;k++) + if(premier(k))printf("%d, ", k); + printf("et c'est tout ce que vous m'avez demandé.\n"); +} diff --git a/C6.2.c b/C6.2.c new file mode 100644 index 0000000..db54454 --- /dev/null +++ b/C6.2.c @@ -0,0 +1,18 @@ +#include + +#define N 30 + +int fib(int k){ + if(k<2) + return 1; + return fib(k-1)+fib(k-2); +} + +int main() { + int n; + do{ + printf("Quel nombre ? "); + scanf("%d",&n); + }while(0>=n || n>=1000); + printf("Voilà votre %d\n", fib(n)); +} diff --git a/C6.6.c b/C6.6.c new file mode 100644 index 0000000..bc110eb --- /dev/null +++ b/C6.6.c @@ -0,0 +1,43 @@ +#include + +#define N 50 + +/** + * Renvoie le couple (F_k, F_k+1) + */ +void fiboRec(int aa[N], int k){ + if(k<=1)aa[k] = 1; + else aa[k] = aa[k-2]+aa[k-1]; + if(k+1 +#include + +#define N 5 +#define BATEAUX_COUNT 2 +#define BATEAUX_LENGTHES_ARR {2,2} +#define J_atoi(x) printf("-----------------------------------\n\e[1;1H\e[2JJoueur %d, c'est à vous: \n",x) +#define printclear() printf("\e[1;1H\e[2J") + +/* + * g==0 -> eau + * g==1 -> eau torpillée + * g==2 -> bateau + * g==3 -> bateau torpillé + */ +typedef int Grille[N][N]; + +void initialiserGrille(Grille grille){ + for(int i=0; i=2; +} + +/** + * dir==0 -> Horizontal + * dir==1 -> Vertical + */ +int setBateau(Grille grille, int longueur, int px, int py, int dir){ + int coefx = dir==0; + int coefy = dir==1; + if((dir!=0) && (dir!=1))return 0; + if((px<0) || (py<0))return 0; + if((px+coefx*longueur >N) || (py+coefy*longueur>N)) return 0; + + for(int i=0; i2); + + if(jeu==0)return 0; + + Grille g1, g2; + + initialiserGrille(g1); + initialiserGrille(g2); + + int bateauxLength[BATEAUX_COUNT] = BATEAUX_LENGTHES_ARR; + + int tx, ty; + + demandeRemplirGrille(g1,bateauxLength); + //remplirAupif(g1, bateauxLength); + + if(jeu==1){ + J_atoi(2); + demandeRemplirGrille(g2, bateauxLength); + }else{ + remplirAupif(g2, bateauxLength); + } + + int batCount=0; + for(int k=0; k +#define N 50 + +/** + * Renvoie le couple (F_k, F_k+1) + */ +void fiboRec(int aa[N], int k){ + if(k<=1)aa[k] = 1; + else aa[k] = aa[k-2]+aa[k-1]; + if(k+1