Advertisement
cd62131

calc e

May 12th, 2019
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define MAX 1000
  4. static void print(char *v1, char *v2, size_t size) {
  5.   for (size_t i = 0; i < size; ++i) {
  6.     printf("%d", v1[i]);
  7.   }
  8.   puts("");
  9.   for (size_t i = 0; i < size; ++i) {
  10.     printf("%d", v2[i]);
  11.   }
  12.   puts("");
  13. }
  14. int main(void) {
  15.   char a[MAX] = {1, 0}, b[MAX] = {0}, c[MAX] = {0};
  16.   c[0] = -1; // dummy
  17.   for (int m = 1; memcmp(b, c, sizeof b); ++m) {
  18.     // print(a, b, MAX);
  19.     memcpy(c, b, sizeof c);
  20.     for (size_t i = 0; i < MAX; ++i) {
  21.       b[i] += a[i];
  22.       for (size_t j = i; 1 <= j && 9 < b[j]; --j) {
  23.         b[j] -= 10;
  24.         ++b[j - 1];
  25.       }
  26.     }
  27.     for (int i = 0, p = 0; i < MAX;
  28.          p *= 10, p += a[i], a[i] = p / m, p %= m, ++i) {
  29.       ;
  30.     }
  31.   }
  32.   printf("%d.", b[0]);
  33.   for (size_t i = 1; i < MAX; ++i) {
  34.     printf("%d", b[i]);
  35.   }
  36.   puts("");
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement