From 72545846ba58416f26f9f6d4ba7b564bc46b9d80 Mon Sep 17 00:00:00 2001 From: nihonium Date: Mon, 14 Feb 2022 16:39:04 +0300 Subject: [PATCH] sum --- numbers/sum.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 numbers/sum.c diff --git a/numbers/sum.c b/numbers/sum.c new file mode 100644 index 0000000..c6199ab --- /dev/null +++ b/numbers/sum.c @@ -0,0 +1,37 @@ +#include +#include + +int pow_(int x, int y) { + if (!y) { + return 1; + } + int res = x; + for (int i = 1; i <= y-1; ++i) { + res = res*x; + } + return res; +} + +int main(int argc, char *argv[]) { + char z[10000]; + if (argc) + strcpy(z, argv[1]); + + float x; + int y; + scanf("%f %x", &x, &y); + + int len = strlen(z); + int res = 0; + for (int i = len-1; i >= 0; --i) { + if (z[i]>=48 && z[i]<=57) { + res += (z[i] - '0') * pow_(27, len-i-1); + } + else { + res += (z[i] - 54) * pow_(27, len-i-1); + } + } + printf("%.3f\n", x+y+res); +} + +