nihonium
/
mipt_clang
Archived
1
0
Fork 0
remotes/private/master
nihonium 3 years ago
parent 959f195b5f
commit 3472194b08

@ -4,7 +4,7 @@
int main() {
char a[1001] = "";
char b[1001] = "";
char res[1002] = ""
char res[1002] = "";
char null = 0;
int len, len_;
int i, j;

@ -0,0 +1,57 @@
#include <stdio.h>
#include <stdlib.h>
#define N 100
struct _Decimal {
char a[N]; // number is a[0]*10^0 + a[1]*10^1 + ..+ a[n]*10^n
unsigned int n;
};
typedef struct _Decimal Decimal;
Decimal zero = {{0}, 0};
Decimal add(Decimal a, Decimal b) {
Decimal c;
char cf = 0;
unsigned int i;
if (a.n < b.n) {
c = a;
a = b;
b = c;
}
c.n = a.n;
for (i = 0; i <= b.n; ++i) {
c.a[i] = (a.a[i] + b.a[i] + cf) % 10;
cf = (int)((a.a[i] + b.a[i] + cf) / 10);
}
for (; i <= a.n; ++i) {
c.a[i] = (a.a[i] + cf) % 10;
cf = (int)((a.a[i] + cf) / 10);
}
if (cf) {
++c.n;
c.a[i] = cf;
}
return c;
}
void print(Decimal x) {
for (int i = x.n; i >= 0; --i)
printf("%d", x.a[i]);
printf("\n");
}
int main(){
Decimal b = {{9, 9, 9}, 2};
Decimal a = {{2}, 0};
Decimal res;
res = add(a, b);
print(res);
return 0;
}