#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define MAX 10000
char * addition(char a[],char b[]){
static char add[MAX];
char c[MAX];
int temp;
int la,lb;
int i,j,k=0,x=0,y;
long int car=0;
long sum = 0;
//printf("\n la=%d lb=%d ",la,lb);
for(i=0;i<=la;i++){ a[i] = a[i] - 48; }
for(i=0;i<=lb;i++){ b[i] = b[i] - 48; }
if(la>lb){
y=0;
k=la;
}
else{
k=lb;
y=1;
}
//printf("\nAddition called ");
for(i=la,j=lb;i>=0,j>=0;i--,j--){
//printf("Addition called ");
c[k--]=(car+a[i]+b[j])%10;
car=(car+a[i]+b[j])/10;
}//for
printf("\nWithout carry %s",c
);
if(y=0){
j=0;
for(i=0;i<la+1;i++){
add[j++]=c[i] + 48;
}
add[j]='\0';
}
else{
j=0;
for(i=0;i<lb+1;i++){
add[j++]=c[i] + 48;
}
add[j]='\0';
}
return add;
}
char * multiply(char a[],char b[]){
static char mul[MAX];
char c[MAX];
char temp[MAX];
int la,lb;
int i,j,k=0,x=0,y;
long int r=0;
long sum = 0;
for(i=0;i<=la;i++){
a[i] = a[i] - 48;
}
for(i=0;i<=lb;i++){
b[i] = b[i] - 48;
}
for(i=lb;i>=0;i--){
r=0;
for(j=la;j>=0;j--){
temp[k++] = (b[i]*a[j] + r)%10;
r = (b[i]*a[j]+r)/10;
}
temp[k++] = r;
x++;
for(y = 0;y<x;y++){
temp[k++] = 0;
}
}
k=0;
r=0;
for(i=0;i<la+lb+2;i++){
sum =0;
y=0;
for(j=1;j<=lb+1;j++){
if(i <= la+j){
sum = sum + temp[y+i];
}
y += j + la + 1;
}
c[k++] = (sum+r) %10;
r = (sum+r)/10;
}
c[k] = r;
j=0;
for(i=k-1;i>=0;i--){
mul[j++]=c[i] + 48;
}
mul[j]='\0';
return mul;
}
int main(){
char a[MAX]={'9','5','5','5','5' };
char b[MAX]={'3','3','3','3','3','3','3','3','3','3'};
char *c;
int la,lb;
//int i = 0;
int i = 1;
//int i = 2;
printf("Answer of two numbers : "); switch(i){
case 0: c = multiply(a,b); break;
case 1: c = addition(a,b); break;
//case 2: c = sub(a,b); break;
default: break;
}
//c = multiply(a,b);
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8bWF0aC5oPgojaW5jbHVkZTxzdGRsaWIuaD4KI2luY2x1ZGU8c3RyaW5nLmg+CiNkZWZpbmUgTUFYIDEwMDAwCgpjaGFyICogYWRkaXRpb24oY2hhciBhW10sY2hhciBiW10pewogICAgCiAgICBzdGF0aWMgY2hhciBhZGRbTUFYXTsKICAgIGNoYXIgY1tNQVhdOwogICAgaW50IHRlbXA7CiAgICBpbnQgbGEsbGI7CiAgICBpbnQgaSxqLGs9MCx4PTAseTsKICAgIGxvbmcgaW50IGNhcj0wOwogICAgbG9uZyBzdW0gPSAwOwogICAgbGE9c3RybGVuKGEpLTE7CiAgICBsYj1zdHJsZW4oYiktMTsKICAgIC8vcHJpbnRmKCJcbiBsYT0lZCBsYj0lZCAiLGxhLGxiKTsKICAgIGZvcihpPTA7aTw9bGE7aSsrKXsgYVtpXSA9IGFbaV0gLSA0ODsgfQogICAgZm9yKGk9MDtpPD1sYjtpKyspeyBiW2ldID0gYltpXSAtIDQ4OyB9CiAgICAKICAgaWYobGE+bGIpewogICAgICAgeT0wOwogICAgICAgaz1sYTsKICAgCiAgIH0KICAgZWxzZXsKICAgICAgIGs9bGI7CiAgICAgICB5PTE7CiAgIH0KICAgIC8vcHJpbnRmKCJcbkFkZGl0aW9uIGNhbGxlZCAiKTsKICAgIGZvcihpPWxhLGo9bGI7aT49MCxqPj0wO2ktLSxqLS0pewogICAgICAgIC8vcHJpbnRmKCJBZGRpdGlvbiBjYWxsZWQgIik7CiAgICAgICAgY1trLS1dPShjYXIrYVtpXStiW2pdKSUxMDsKICAgICAgICBjYXI9KGNhcithW2ldK2Jbal0pLzEwOwogICAgfS8vZm9yCiAgICBwcmludGYoIlxuV2l0aG91dCBjYXJyeSAlcyIsYyk7CiAgICAKICAgIGlmKHk9MCl7CiAgICAgICAgaj0wOwogICAgICAgIGZvcihpPTA7aTxsYSsxO2krKyl7CiAgICAgICAgYWRkW2orK109Y1tpXSArIDQ4OwogICAgICAgIH0KICAgICAgICBhZGRbal09J1wwJzsKICAgIH0KICAgIGVsc2V7CiAgICAgICAgaj0wOwogICAgICAgIGZvcihpPTA7aTxsYisxO2krKyl7CiAgICAgICAgYWRkW2orK109Y1tpXSArIDQ4OwogICAgICAgIH0KICAgICAgICBhZGRbal09J1wwJzsKICAgIH0KICAgIHJldHVybiBhZGQ7Cgp9CgoKY2hhciAqIG11bHRpcGx5KGNoYXIgYVtdLGNoYXIgYltdKXsKICAgIHN0YXRpYyBjaGFyIG11bFtNQVhdOwogICAgY2hhciBjW01BWF07CiAgICBjaGFyIHRlbXBbTUFYXTsKICAgIGludCBsYSxsYjsKICAgIGludCBpLGosaz0wLHg9MCx5OwogICAgbG9uZyBpbnQgcj0wOwogICAgbG9uZyBzdW0gPSAwOwogICAgbGE9c3RybGVuKGEpLTE7CiAgICBsYj1zdHJsZW4oYiktMTsKICAgCiAgICAgICAgZm9yKGk9MDtpPD1sYTtpKyspewogICAgICAgICAgICAgICAgYVtpXSA9IGFbaV0gLSA0ODsKICAgICAgICB9CgogICAgICAgIGZvcihpPTA7aTw9bGI7aSsrKXsKICAgICAgICAgICAgICAgIGJbaV0gPSBiW2ldIC0gNDg7CiAgICAgICAgfQoKICAgIGZvcihpPWxiO2k+PTA7aS0tKXsKICAgICAgICAgcj0wOwogICAgICAgICBmb3Ioaj1sYTtqPj0wO2otLSl7CiAgICAgICAgICAgICB0ZW1wW2srK10gPSAoYltpXSphW2pdICsgciklMTA7CiAgICAgICAgICAgICByID0gKGJbaV0qYVtqXStyKS8xMDsKICAgICAgICAgfQogICAgICAgICB0ZW1wW2srK10gPSByOwogICAgICAgICB4Kys7CiAgICAgICAgIGZvcih5ID0gMDt5PHg7eSsrKXsKICAgICAgICAgICAgIHRlbXBbaysrXSA9IDA7CiAgICAgICAgIH0KICAgIH0KICAgCiAgICBrPTA7CiAgICByPTA7CiAgICBmb3IoaT0wO2k8bGErbGIrMjtpKyspewogICAgICAgICBzdW0gPTA7CiAgICAgICAgIHk9MDsKICAgICAgICAgZm9yKGo9MTtqPD1sYisxO2orKyl7CiAgICAgICAgICAgICBpZihpIDw9IGxhK2opewogICAgICAgICAgICAgICAgIHN1bSA9IHN1bSArIHRlbXBbeStpXTsKICAgICAgICAgICAgIH0KICAgICAgICAgICAgIHkgKz0gaiArIGxhICsgMTsKICAgICAgICAgfQogICAgICAgICBjW2srK10gPSAoc3VtK3IpICUxMDsKICAgICAgICAgciA9IChzdW0rcikvMTA7CiAgICB9CiAgICBjW2tdID0gcjsKICAgIGo9MDsKICAgIGZvcihpPWstMTtpPj0wO2ktLSl7CiAgICAgICAgIG11bFtqKytdPWNbaV0gKyA0ODsKICAgIH0KICAgIG11bFtqXT0nXDAnOwogICAgcmV0dXJuIG11bDsKfQoKaW50IG1haW4oKXsKICAgIGNoYXIgYVtNQVhdPXsnOScsJzUnLCc1JywnNScsJzUnIH07CiAgICBjaGFyIGJbTUFYXT17JzMnLCczJywnMycsJzMnLCczJywnMycsJzMnLCczJywnMycsJzMnfTsKICAgIGNoYXIgKmM7CiAgICBpbnQgbGEsbGI7CiAgICAvL2ludCBpID0gMDsKICAgIGludCBpID0gMTsKICAgIC8vaW50IGkgPSAyOwoKICAgIHByaW50ZigiQW5zd2VyIG9mIHR3byBudW1iZXJzIDogIik7CiAgICBzd2l0Y2goaSl7CiAgICAgICAgY2FzZSAwOiAgYyA9IG11bHRpcGx5KGEsYik7IGJyZWFrOwogICAgICAgIGNhc2UgMTogIGMgPSBhZGRpdGlvbihhLGIpOyBicmVhazsKICAgICAgICAvL2Nhc2UgMjogIGMgPSBzdWIoYSxiKTsgYnJlYWs7CiAgICAgICAgZGVmYXVsdDogYnJlYWs7CiAgICB9CiAgICAvL2MgPSBtdWx0aXBseShhLGIpOwogICAgcHJpbnRmKCIlcyIsYyk7CiAgICByZXR1cm4gMDsKfQoK