problem
#include <stdio.h>
#include<string.h>>
int main() {
char a[100],b[100];
int lena,lenb,x,y,num1,num2,cry,sum,i,j;
while(scanf("%s%s",&a,&b)==2)
{
if(a[0]=='0'&&b[0]=='0')
break;
lena=strlen(a);
lenb=strlen(b);
x=0;
cry=0;
for(i=lena-1,j=lenb-1;i>=0||j>=0;j--,i--)
{
if(i>=0)
num1=a[i]-48;
else num1=0;
if(j>=0)
num2=b[j]-48;
else num2=0;
sum=num1+num2+x;
if(sum>9)
{
cry++;
x=sum/10;
}
else x=0;
}
if(cry==0)
printf("No carry operation.\n");
else if(cry==1)
printf("%d carry operation.\n",cry);
else
printf("%d carry operations.\n",cry);
}
return 0;
}
No comments:
Post a Comment