TP08 Boucles (encore)

This commit is contained in:
HORVILLE 2021-09-28 16:20:58 +02:00
parent 8a59a181a1
commit abbd939ddc
2 changed files with 39 additions and 0 deletions

20
APL1.1/TP08/diviseur.c Normal file
View File

@ -0,0 +1,20 @@
#include<stdio.h>
#include<stdlib.h>
int pgcd(int a, int b) {
if (b == 0) return a;
else if (a == 0) return b;
else {
return pgcd(b, a % b);
}
}
int main(int argc, char * argv[]) {
int v1, v2;
printf("Veuillez donner deux entiers : ");
scanf("%d %d", &v1, &v2);
printf("Le plus grand diviseur commun entre %d et %d est %d\n", v1, v2, pgcd(v1, v2));
return EXIT_SUCCESS;
}

19
APL1.1/TP08/sapin.c Normal file
View File

@ -0,0 +1,19 @@
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char * argv[]) {
int height;
printf("Hauteur ? ");
scanf("%d", &height);
printf("\n");
for (int i = 0; i <= height; i++) {
for (int i2 = height-i; i2 > 0; i2--) printf(" ");
for (int i2 = 0; i2 < i*2-1; i2++) printf("*");
printf("\n");
}
return EXIT_SUCCESS;
}