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
|
#include<iostream>
#include<cmath>
using namespace std;
const int ARRAY_SIZE = 20;
void fillZero(int conInput1[], int conInput2[], int output[]);
void mod1(int conInput1[], int conInput2[], int output[], int& trans);
void remainder(int conInput1[], int conInput2[], int output[]);
void carry(int conInput1[], int conInput2[], int output[], int& trans);
void addition(int conInput1[], int conInput2[], int output[], int& trans);
void printResults(int conInput1[], int conInput2[], int output[]);
int main()
{
int conInput1[ARRAY_SIZE];
int conInput2[ARRAY_SIZE];
int output[ARRAY_SIZE];
int trans;
fillZero(conInput1, conInput2, output);
addition(conInput1, conInput2, output, trans);
printResults(conInput1, conInput2, output);
return 0;
}
void fillZero(int conInput1[], int conInput2[], int output[])
{
for ( int i = 0; i < ARRAY_SIZE; i++ )
{
conInput1[i] = 9;
conInput2[i] = 9;
output[i] = 0;
/*cout << conInput1[i];
cout << conInput2[i];
cout << output[i];*/
}
}
void mod1(int conInput1[], int conInput2[], int output[], int& trans)
{
for ( int i = 0; i < ARRAY_SIZE; i++ )
{
double val2;
double val1;
double sum = output[i];
val1 = sum / 10;
modf(val1, &val2);
//cout << endl << sum;
//cout << endl << val1;
//cout << endl << &val2 << "...";
//cout << endl << modf(val1, &val2);
//cout << x;
int trans = 0;
trans = int (&val2);
//cout << trans << " trans";
}
}
void remainder(int conInput1[], int conInput2[], int output[])
{
for ( int i = 0; i < ARRAY_SIZE; i++ )
{
int sum1 = 0;
sum1 = output[i] % 10;
output[i] = sum1;
//cout << endl << sum1;
}
}
void carry(int conInput1[], int conInput2[], int output[], int& trans)
{
//cout << trans;
for ( int i = 0; i < ARRAY_SIZE; i++ )
{
int sum2 = output[i] + trans;
//cout << sum2;
}
}
void addition(int conInput1[], int conInput2[], int output[], int& trans)
{
for ( int i = 0; i < ARRAY_SIZE; i++ )
{
output[i] = conInput1[i] + conInput2[i];
//cout << output[i];
if ( output[i] > 9 )
{
mod1(conInput1, conInput2, output, trans);
remainder(conInput1, conInput2, output);
carry(conInput1, conInput2, output, trans);
}
}
}
void printResults(int conInput1[], int conInput2[], int output[])
{
cout << endl << endl;
for ( int i = 0; i < ARRAY_SIZE; i++ )
{
cout << conInput1[i];
}
cout << endl;
for ( int j = 0; j < ARRAY_SIZE; j++ )
{
cout << conInput2[j];
}
cout << endl << "--------------------" << endl;
for ( int i = 0; i < ARRAY_SIZE; i++ )
{
cout << output[i];
}
cout << endl << endl;
}
| |