-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem08.c
More file actions
65 lines (59 loc) · 1.15 KB
/
problem08.c
File metadata and controls
65 lines (59 loc) · 1.15 KB
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
64
65
#include <stdio.h>
#include <stdlib.h>
void motivationMsg()
{
printf("THE PAIN YOU FEEL TODAY IS THE STRENGTH YOU FEEL TOMORROW\n");
return;
}
void getWorkoutDays(int *n)
{
while (1)
{
printf("Enter the no of training days (1 - 20): ");
scanf("%d", n);
if (*n >= 1 && *n <= 20)
{
if (*n > 10)
motivationMsg();
break;
}
printf("!! Invalid Input !!\n");
}
}
void printWaveChart(int n)
{
int totalNumbers = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n - i; j++)
{
printf(" ");
}
if (i % 2 == 1)
{
for (int k = 1; k <= i; k++)
{
printf("%3d", k);
totalNumbers++;
}
}
else
{
for (int k = i; k >= 1; k--)
{
printf("%3d", k);
totalNumbers++;
}
}
printf("\n");
}
printf("Total numbers printed: %d", totalNumbers);
return;
}
int main()
{
int n;
getWorkoutDays(&n);
printWaveChart(n);
return 0;
}