-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw_9.c
54 lines (45 loc) · 1.11 KB
/
hw_9.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
#include<stdio.h>
int evenDigitsCount(int number);
int sumDigits(int number);
int xPower(int x, int power);
int main() {
int number = 123;
int evenDigitsCounts = evenDigitsCount(number);
int sumDigit = sumDigits(number);
int x = 0;
int power = 0;
printf("xPower = %d\n", xPower(x, power));
printf("sum digits = %d\n", sumDigit);
printf("return Numbers = %d\n", evenDigitsCounts);
return 0;
}
int evenDigitsCount(int number) {
int numberForMinus = 0, numberForIf = 0, count = 0;
while (number != 0) {
numberForMinus = (number / 10) * 10;
numberForIf = number - numberForMinus;
number = numberForMinus / 10;
if (numberForIf % 2 == 0) {
count++;
}
}
return count;
}
int sumDigits(int number) {
int numberForMinus = 0, numberForPlus = 0, count = 0;
while (number > 0) {
numberForMinus = (number / 10) * 10;
numberForPlus = number - numberForMinus;
count += numberForPlus;
number = numberForMinus / 10;
}
return count;
}
int xPower(int x, int power) {
int result = 1;
while (power != 0) {
result *= x;
power--;
}
return result;
}