新鲜的程序出炉喽
减法来了
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main()
{
int borrow,a[100]={0},b[100]={0},c[100],i,len,len1,len2,flag;
char s1[100],s2[100];
scanf("%s %s",s1,s2);
len1=strlen(s1);
len2=strlen(s2);
if(len1<len2)
flag=1;
else if(len1==len2)
for(i=0;i<len1;i++)
if(s1[i]<s2[i])
{
flag=-1;
break;
}
if(flag>0)
{
for(i=0;i<len1;i++)
a[i]=s1[len1-1-i]-'0';
for(i=0;i<len2;i++)
b[i]=s2[len2-1-i]-'0';
}
else
{
for(i=0;i<len1;i++)
b[i]=s1[len1-1-i]-'0';
for(i=0;i<len2;i++)
a[i]=s2[len2-1-i]-'0';
}
len=len1>len2?len1:len2;
borrow=0;
for(i=0;i<len;i++)
{
c[i]=a[i]-b[i]-borrow;
borrow=c[i]<0;
if(borrow>0)
c[i]+=10;
/*if(c[i]<0)
{
c[i]+=10;
borrow=1;
}
else
borrow=0;
*/
}
while(c[len-1]==0&&len>1)
len--;
if(flag<0)
putchar('-');
for(i=len-1;i>=0;i--)
printf("%d",c[i]);
getch();
}