#Help with code
1 messages · Page 1 of 1 (latest)
#include <iostream>
using namespace std;
int main() {
const int N = 50;
short int a[N] = { 0,8,9,8,1,7,2,8,3,9,4,8,1,2,2,1,1,7,6,7,5,8,3,9,2,6,1,2,3,3,2,3,9,8,9,0,4,9,3,9,9,4,5,7,3,2,1,1,2,2};
short int b[N] = { 0,3,7,8,2,3,9,1,3,9,6,5,4,3,2,1,1,1,7,8,2,3,3,9,9,7,7,8,8,6,5,4,5,5,2,3,3,2,4,5,9,8,1,2,3,1,7,8,2,7};
short int c[N];
for (int j=N-1; j>=0; j--)
{
c[j]=a[j]+b[j];
if(c[j] > 9){
c[j - 1] += c[j] / 10;
c[j] %= 10;
}
}
for (int j=0; j < N; j++)
cout << c[j];
cout << endl;
}
this is what i got
number it outputs 01663019680355422835716813801977431371748269638949
Uhm, what you are doing here isn't what the prompt is asking you to do
You gotta sum up two large number, not two arrays.
for example:
;compile cpp
#include <iostream>
using namespace std;
int main()
{
const int N = 4;
short int a[N] = { 0,8,9,8102}; // largest num is 8102
short int b[N] = { 0,3,7,88,}; // largest num is 88
short int c[2] = {0, 0};
for(int i= 0; i < N; i++)
{
if( a[i] > c[0])
{
c[0] = a[i];
}
if( b[i] > c[1])
{
c[1] = b[i];
}
}
cout << c[0] << " + " << c[1] << " = ";
cout << c[0] + c[1] << endl; // 8102 + 88 = 8190
}
8102 + 88 = 8190
that's not it XD
it's for scientific calculus I would presume; the maximum values of any interger variable, even unsigned long long whatever, is finite
so the only way to define the input value is indeed either an array or many bytes of any data, contiguous in a struct