哪位大哥帮我改改》

作者在 2010-10-30 17:35:25 发布以下内容
 

写程序求两个相同位数的大整数之和

两个大整数(位数不超过1000)
Output

两个大整数的和

Sample Input
1234567890 1234567890 111111111111 222222222222
Sample Output
2469135780 333333333333
 
#include <stdio.h>
#include <string.h>
#define MAXSIZE 1002
int main()
{
    int i,temp=0,k,j;
    char a[MAXSIZE];
    char  b[MAXSIZE],c[MAXSIZE];
        scanf("%s",a);
        scanf("%s",b);
    int lengtha=strlen(a)/sizeof(a[0]);
    int lengthb=strlen(b)/sizeof(b[0]);
    if(lengtha==lengthb)
    {
        for(i=lengtha ;i>=0;i--)
        {
            k=a[i]+b[i];
            if(k>=10)
            {
                temp=1;
                c[i+1]=k-10;
            }
            else if(k<10)
            {
                j=k+temp;
                if(j==10)
                {
                    temp=1;
                    c[i+1]=0;
                }
                else if(j<10)
                    c[i+1]=j;
            }
        }
    }
    c[0]=temp;
    if(c[0]==0)
    {
            printf("%s",c);
    }
    if(c[0]==1)
        
            printf("%s",c);
    printf("\n");
    return 0;
}
默认分类 | 阅读 786 次
文章评论,共0条
游客请输入验证码
浏览10595次
最新评论