0
sum two string have 30 digits (example input:1,3 out put 1+3=4),how do i fix it ?
#include<iostream> #include<string.h> using namespace std; int main() { bool correct = true; char a[31],b[31],c[33]; cout<<"enter two number\n"; cout<<"a = "; cin>>a; cout<<"b = "; cin>>b; int i,l,L;double n=0,m=0,sum = 0; l = strlen(a); L = strlen(b); for(i=0 ; i<31 ; i++) { if(a[i]>='0'&&a[i]<='9') n = n*10 + (a[i]-'0'); } for(i=0 ; i<31 ; i++) { if(b[i]>='0' && b[i]<='9') m = m*10 + (b[i]-'0'); } for(i=0 ; i<33 ; i++) { c[i] = a[i]+b[i]; if(c[i]>'9') c[i] = c[i]%10; c[i+1]= c[i+1]+1; } for(i=0 ; i<33 ; i++) { if(c[i]>='0' && c[i]<=9) sum = sum*10 + (c[i]-'0'); } cout<<"sum = "<<sum; } \\what is wrong my program
0 Answers