-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriangle.c
More file actions
42 lines (37 loc) · 727 Bytes
/
triangle.c
File metadata and controls
42 lines (37 loc) · 727 Bytes
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
#include <stdio.h>
int min(int a, int b){
if(a > b)
return b;
else
return a;
}
int main() {
int x, y;
int base, hauteur;
int t;
printf("TRIANGLE \n");
printf("base: ");
scanf("%d", &base);
printf("hauteur: ");
scanf("%d", &hauteur);
if(base%2 == 0)
base++;
printf("TRIANGLE: base=%d hauteur=%d\n", base, hauteur);
for ( y = 0; y < hauteur; y++) {
for (x = 0; x < base; x++) {
if (y == 0 && x==base/2)
printf(".");
else if(x ==base/2-y)
printf("/");
else if(x ==base/2+y)
printf("\\");
else
if(y==min(hauteur-1, base/2) && x>(base/2)-y && x<(base/2)+y)
printf("_");
else
printf(" ");
}
printf("\n");
}
return 0;
}