-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem_016.c
68 lines (57 loc) · 1.07 KB
/
Problem_016.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
#include <stdio.h>
#include <stdlib.h>
int main()
{
int number[1000];
int result;
int base;
int power;
printf("Please input the base:");
scanf("%d", &base);
printf("\nPlease input the power:");
scanf("%d", &power);
int counter;
for(counter = 0; counter < 1000; counter++)
{
number[counter] = 0;
}
number[999] = 1;
int times = 0;
int multiplicand;
int multiplier;
multiplier = base;
int remaining = 0;
while(times < power)
{
for(multiplicand = 999; multiplicand >= 0; multiplicand--)
{
result = (number[multiplicand] * multiplier) + remaining;
remaining = 0;
if(result >= 10)
{
remaining = result / 10;
result %= 10;
}
number[multiplicand] = result;
}
times++;
}
int print = 0;
result = 0;
for(counter = 0; counter < 1000; counter++)
{
if(number[counter] != 0 && print == 0)
{
printf("%d", number[counter]);
result += number[counter];
print = 1;
}
else if(print == 1)
{
printf("%d", number[counter]);
result += number[counter];
}
}
printf("The result is: %d\n", result);
return 0;
}