Question
1.Correct the logic/syntax error in the code below to produce the correct output, WITHOUT CHANGING ITS FLOW. 2. Explain in detail the reason/concept behind error.
1.Correct the logic/syntax error in the code below to produce the correct output, WITHOUT CHANGING ITS FLOW.
2. Explain in detail the reason/concept behind error.
Code without template works perfectly fine, here is the output without templates:
DO NOT CHANGE THE FLOW OF THE PROGRAM.
Code for reference:
# include
using namespace std;
template
class HugeInt{
public:
int i;
int sum;
T arr[20];
void setArray(){
for(i=0;i
cin>>arr[i];
}}
void s(T&x, T&y){//CHECK
int c=0;
T res;
for (i = 0; i
{
if(i==19){
res.arr[i]=x.arr[i]+y.arr[i]+c;
}
else {res.arr[i]=(x.arr[i]+y.arr[i]+c)%10;}
c=(x.arr[i]+y.arr[i])/10;
}
for (i = 19; i >=0; i--)
{
cout
}
}
};
int main(){
HugeInt x,y,res;
cout
x.setArray();
cout
y.setArray();
res.s(x,y);
return 0;
}
112345678912345678912ENTERSECOND20DIGITINTEGER
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started