-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10035(primaryarith).cpp
117 lines (111 loc) · 1.62 KB
/
10035(primaryarith).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include<stdio.h>
#include<string.h>
int main()
{
unsigned int x,y;
long int i,m,n,a,len,len1,len2,zero,count,carry,add,b;
char num1[11],num2[11];
while(scanf("%u %u",&x,&y))
{
if(x==0 && y==0)
break;
m=x;
n=y;
i=0;
while(m!=0)
{
m=m/10;
i++;
}
len1=i;
i=0;
while(n!=0)
{
n=n/10;
i++;
}
len2=i;
if(len1>len2)
{
len=len1;
for(i=len-1;i>=0;i--)
{
a=x%10;
num1[i]=a+'0';
x=x/10;
}
num1[len]='\0';
zero=len1-len2;
for(i=0;i<zero;i++)
num2[i]='0';
for(i=len-1;i>=zero;i--)
{
a=y%10;
num2[i-1]=a+'0';
y=y/10;
}
num2[len]='\0';
}
else if(len2>len1)
{
len=len2;
for(i=len-1;i>=0;i--)
{
a=y%10;
num2[i]=a+'0';
y=y/10;
}
num2[len]='\0';
zero=len2-len1;
for(i=0;i<zero;i++)
num1[i]='0';
for(i=len-1;i>=zero;i--)
{
a=x%10;
num1[i]=a+'0';
x=x/10;
}
num1[len]='\0';
}
else
{
len=len1;
for(i=len-1;i>=0;i--)
{
a=x%10;
num1[i]=a+'0';
x=x/10;
}
num1[len]='\0';
for(i=len-1;i>=0;i--)
{
a=y%10;
num2[i]=a+'0';
y=y/10;
}
num2[len]='\0';
}
count=0;
carry=0;
for(i=len-1;i>=0;i--)
{
a=num1[i]-'0';
b=num2[i]-'0';
add=a+b+carry;
if(add>9)
{
carry=add/10;
count++;
}
else
carry=0;
}
if(count==0)
printf("No carry operation.\n");
else if(count==1)
printf("%u carry operation.\n",count);
else if(count>1)
printf("%u carry operations.\n",count);
}
return 0;
}