please help!!!!!
I wrote this program to calculate addtition and subtraction of two large numbers (maximum 100 digit)
it won't work for minus numbers :(
i know it have problems but i couldn't fix them,please help me for fixing this :)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,d=0,la,lb,max,ia,ib,ix,iy;
char a[100],b[100],pos[101],neg[101],x[100],y[100];
printf("Enter First Number: \n");
scanf("%s",a);
printf("Enter Second Number: \n");
scanf("%s",b);
for(i=0;a[i]!='\0';i++)
x[i]=a[i];
x[i]='\0';
for(i=0;b[i]!='\0';i++)
y[i]=b[i];
y[i]='\0';
for(i=0; a[i]!='\0';i++);
la=i;
for(i=0; b[i]!='\0';i++);
lb=i;
if(la>lb)
max=la;
else
max=lb;
ia=la-1;
ib=lb-1;
ix=ia;
iy=ib;
for(i=max;i>=0;i--)
{
if(ia==-1)
{
ia=0;
a[ia]='0';
}
if(ib==-1)
{
ib=0;
b[ib]='0';
}
pos[i]=((a[ia]-48)+(b[ib]-48)+d)%10;
d=((a[ia]-48)+(b[ib]-48)+d)/10;
ia--;
ib--;
}
printf("a+b=");
if(pos[0]!=0)
for(i=0;i<=max;i++)
{
printf("%d",pos[i]);
}
else if(pos[0]==0)
for(i=1;i<=max;i++)
{
printf("%d",pos[i]);
}
printf("\n");
for(i=max;i>=0;i--)
{
if(ix==-1)
{
ix=0;
x[ix]='0';
}
if(iy==-1)
{
iy=0;
y[iy]='0';
}
if((x[ix]-48)-(y[iy]-48)<0)
{
x[ix]+=10;
x[ix-1]-1;
neg[i]=(x[ix]-48)-(y[iy]-48);
ix--;
iy--;
}
else
{
neg[i]=(x[ix]-48)-(y[iy]-48);
ix--;
iy--;
}
}
printf("a-b=");
if(pos[0]!=0)
for(i=0;i<=max;i++)
printf("%d",neg[i]);
else if(pos[0]==0)
for(i=1;i<=max;i++)
printf("%d",neg[i]);
return 0;
}