HDU-1002 大数A+B

这道题是模拟加法的,没什么难度。

#include<stdio.h>
#include<string.h>
char st1[1005],st2[1005];
int st3[2005];
void Add()
{
	int i1=strlen(st1)-1,i2=strlen(st2)-1;
	int carry=0,tmp,i,j=0;
    for(;i1>=0&&i2>=0;--i1,--i2,++j){
		tmp=st1[i1]-'0'+st2[i2]-'0'+carry;
		st3[j]=tmp%10;
		carry=tmp/10;
    }
    while(i1>=0){
		tmp=st1[i1--]-'0'+carry;
		st3[j++]=tmp%10;
		carry=tmp/10;
    }
    while(i2>=0){
		tmp=st2[i2--]-'0'+carry;
		st3[j++]=tmp%10;
	    carry=tmp/10;
    }
    if(carry) st3[j++]=carry;
    printf("%s + %s = ",st1,st2);
    for(i=j-1;i>=0;i--)
    printf("%d",st3[i]);
    printf("\n");
}
int main()
{
	int t,cas=1;
	scanf("%d",&t);
	while(t--){
		scanf("%s %s",st1,st2);
		printf("Case %d:\n",cas++);	
		Add();	
		if(t) printf("\n");
	}
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值