-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupsideDownTriangle.c
63 lines (50 loc) · 1.19 KB
/
upsideDownTriangle.c
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <stdlib.h>
#define inferior_limit 3
#define superior_limit 20
void upsideDownTriangle(int rows);
int readingRows();
int validating_Rows(int rows);
int main()
{
int TRIANGLE_DIM = readingRows();
upsideDownTriangle(TRIANGLE_DIM);
return 0;
}
int readingRows()
{
int number;
printf("Enter rows%d and %d: ", inferior_limit, superior_limit);
scanf("%d", &number);
while(!validating_Rows(number))
{
printf("Error. Enter again: ");
fflush(stdin);
scanf("%d", &number);
}
return number;
}
int validating_Rows(int rows)
{
return rows >= inferior_limit && rows <= superior_limit;
}
void upsideDownTriangle(int rows)
{
int counterSpaces = 0;
int i = 0;
int counterSymbols = 0;
for(i = 0; i < rows; i++)
{
for(int j = 0; j < counterSpaces; j++)
{
printf("%c", ' ');
}
for(int j = 0; j < counterSymbols; j++)
{
printf("%d ", rand()%5 + 1);
}
counterSpaces++;
counterSymbols = rows - counterSpaces;
printf("\n");
}
}