-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem 20.cpp
48 lines (42 loc) · 1.07 KB
/
Problem 20.cpp
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
#include<iostream>
#include<cmath>
#include <cstdlib>
using namespace std;
void multiply(int base);
#define ARRAYSIZE 2048
short product [ARRAYSIZE];
const int productLength = ARRAYSIZE;
int main(){
long exponet = 1000;
long base = 2;
cout << "Enter a positive Base as an integer to factorilize: ";
cin >> base;
product[0] = 1;
for(int i = 1; i <= base; i++){
multiply(i);
for (int pos = 0; pos < productLength; pos++){//goes through digits
for (double y = 0; product[pos] >= pow(10, y); y++){//Carrys digits accordingly
if (y != 0){
int YInt = y;
product[pos + YInt] += floor(product [pos] / pow(10, y));
product[pos] -= floor(product [pos] / pow(10, y)) * 10;
}
}
}
}
for (int x = productLength - 1; x >= 0 ; x--){
cout << product[x] << " ";
}
cout << endl << endl;
long long tempSum = 0;
for (int x = 0; x < ARRAYSIZE; x++){
tempSum += product[x];
}
cout << tempSum << endl;
system("PAUSE");
}
void multiply(int base){
for (int x = productLength - 1; x >= 0 ; x--){
product[x] *= base;
}
}