-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem_020.c
More file actions
94 lines (86 loc) · 1.92 KB
/
Problem_020.c
File metadata and controls
94 lines (86 loc) · 1.92 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
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
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int result[1000] = {0};
int multiplicand[1000] = {0};
int multiplier[1000] = {0};
int calculation[1000] = {0};
int digitPlier;
int digitPlicand;
int number;
int numberSaved;
int digit;
int position = 999;
printf("Please input the number for factorialization.\n");
printf("Number:");
scanf("%d", &number);
numberSaved = number;
while(number > 0 && position >= 0) //pernaw ston pinaka ton arithmo.
{
digit = number % 10;
number = number / 10;
multiplicand[position] = digit;
position--;
}
number = numberSaved;
int remaining = 0;
int times = 0;
int counter;
while(number != 2)
{
for(counter = 0; counter < 1000; counter++)
{
multiplier[counter] = 0;
}
position = 999;
number--;
numberSaved = number;
while(number > 0 && position >= 0) //pernaw ston pinaka ton arithmo.
{
digit = number % 10;
number = number / 10;
multiplier[position] = digit;
position--;
}
number = numberSaved;
position = 999;
remaining = 0;
for(digitPlier = 999; digitPlier >= 0; digitPlier--)
{
position = digitPlier;
for(digitPlicand = 999; digitPlicand >= 0; digitPlicand--)
{
result[position] += remaining + (multiplicand[digitPlicand] * multiplier[digitPlier]);
remaining = 0;
if(result[position] >= 10)
{
remaining = result[position] / 10;
result[position] = result[position] % 10;
}
if(position > 0)
{
position--;
}
}
}
for(position = 0; position < 1000; position++)
{
printf("%d", calculation[position]);
multiplicand[position] = result[position];
calculation[position] = result[position];
result[position] = 0;
}
printf("With number: %d\n", number);
printf("\n");
times++;
}
int sum = 0;
for(position = 0; position < 1000; position++)
{
sum = sum + calculation[position];
}
printf("Remaining: %d\n", remaining);
printf("Result:%d\n", sum);
return 0;
}