enter first number: 2323232900990909909878897687687798890
enter 2nd number: 5456456456455455554545454545454545645
Answer is : ???
#include<stdio.h>
#include<string.h>
int main(){
int x[1000],y[1000],z[1000];
int q=0,w=0,e=0;
int t = 0,i;
char num1[255],num2[255],*pa,*pb;
printf("Enter first number : ");
scanf("%s",&num1);
printf("\nEnter second number : ");
scanf("%s",&num2);
pa = num1;
pb = num2;
while(*pa){
x[q++] = *pa++ - 48;
}
while(*pb){
y[w++] = *pb++ - 48;
}
if(q<w){
for(i = q;i > 0;i--){
z[e++]= ((x[i-1] + y[--w]) + t)%10;
t = ((x[i-1] + y[w]) + t)/10;
}
while(w>0){
z[e++] = x[--w] + t;
t= 0;
}
}
else{
for(i = w;i > 0;i--){
z[e++]= ((y[i-1] + x[--q]) + t)%10;
t= ((y[i-1] + x[q]) + t)/10;
}
if(q==0 && t==1)
z[e++] = t;
while(q>0){
z[e++] = x[--q] + t;
t = 0;
}
}
printf("\n");
printf("Sum of both number is : ");
for(i=e-1;i>=0;i--){
printf("%d",z[i]);
}
printf("\n");
return 0;
}
No comments:
Post a Comment