-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcw_10.c
127 lines (105 loc) · 2.05 KB
/
cw_10.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include<stdio.h>
void displayReversNumber();
void displayWeekDay();
int bankPercent(float startAmount, float persent, float goalAmount);
void password(int pas);
void pensiya(int sum);
int main() {
int number;
// displayReversNumber();
// displayWeekDay();
// printf("to reach goal amount is necessary %d years\n", bankPercent(3000, 7.5, 1000000));
// password(12345);
pensiya(15000);
return 0;
}
void displayReversNumber() {
int a;
do {
printf("Enter your positive number:\n");
fflush(stdout);
scanf("%d", &a);
} while (a <= 0);
printf("revers of %d = ", a);
while (a > 0) {
printf("%d", a % 10);
a /= 10;
}
printf("\n");
}
void displayWeekDay() {
int day;
do {
printf("Enter weekday as number from 1 to 7:\n");
fflush(stdout);
scanf("%d", &day);
} while (day <= 0 || day >= 8);
switch (day) {
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Friday");
break;
case 6:
printf("Saturday");
break;
case 7:
printf("Sunday");
break;
}
}
int bankPercent(float startAmount, float persent, float goalAmount) {
int years = 0;
float sum = startAmount;
while (sum < goalAmount) {
sum += sum * persent / 100;
sum *= 100;
sum = ((int) sum) / 100.;
years++;
}
return years;
}
void password(int pas) {
int n;
int count = 0;
do {
printf("Enter your password:\n");
fflush(stdout);
scanf("%d", &n);
count++;
} while (n != pas && count < 3);
if (n != pas) {
printf("I call to police!!!\n");
return;
}
printf("Welcome! Password is correct!\n");
}
void pensiya(int sum) {
float persent = 3.;
int goalAmount = sum * 12 / persent * 100;
int startAge = 20;
int finalAge = 65;
int monthPay = 0;
float total = 0;
do {
int count = 0;
total = 0;
monthPay+=100;
while (count <= (finalAge - startAge) * 12) {
total += total * persent / 100 / 12 + monthPay;
count++;
}
} while (total < goalAmount);
printf("monthly pay = %d;\n", monthPay);
printf("total = %f;\n", total);
}