-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemo1.c
83 lines (69 loc) · 1.29 KB
/
Demo1.c
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
#include <stdio.h>
#include <string.h>
int main()
{
char str1[100];
char str2[100];
int a1, a2;
int b1, b2;
int f, f1, f2;
int len;
int i, j, k;
int power = 1;
k = 2;
while(k--)
{
scanf("%s", str1);
len = strlen(str1);
for(i = 0; i < len; ++i)
{
if(str1[i] == '.')
break;
str2[i] = str1[i];
}
str2[i] = '\0';
a1 = atoi(str2);
strcpy(str2, str1 + i + 1);
a2 = atoi(str2);
f2 = len - i - 1;
if(k == 1)
{
b1 = a1;
b2 = a2;
f1 = f2;
}
}
f = f1>f2?f1:f2;
if(f1 != f)
{
for(i = 0; i < f - f1; ++i)
b2 *= 10;
}
else if(f2 != f)
{
for(i = 0; i < f - f2; ++i)
a2 *= 10;
}
k = f;
while(k--)
power *= 10;
a2 += b2;
a1 += b1;
if(a2 / power != 0)
{
a2 = a2 % power;
a1++;
}
itoa(a2, str2, 10);
memset(str1, 0, 100);
len = strlen(str2);
for(i = 0; i < f - len; ++i)
strcat(str1, "0");
itoa(a2, str2, 10);
strcat(str1, str2);
itoa(a1, str2, 10);
strcat(str2, ".");
strcat(str2, str1);
printf("%s\n", str2);
return 0;
}