Advertisement
hd1

Untitled

hd1
Oct 9th, 2014
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include <math.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. int main (int argc, char** argv) {
  5.   double pi_d = 3.14159265358979323846;
  6.   double sin_d = sin(pi_d);
  7.   printf("pi = %.33f\n   + %.33f\n", pi_d, sin_d);
  8.  
  9.   char pi_s[100]; char sin_s[100]; char result_s[100] = {};
  10.   snprintf(pi_s, sizeof(pi_s), "%.33f",pi_d);
  11.   snprintf(sin_s, sizeof(sin_s), "%.33f", sin_d);
  12.   int carry = 0;
  13.   for (int i = strlen(pi_s) ;i >= 0; --i) {
  14.     result_s[i] = pi_s[i];
  15.     if (pi_s[i] != '.') {
  16.       char d = pi_s[i] + sin_s[i] + carry - '0' * 2;
  17.       carry = d > 9;
  18.       result_s[i] = d % 10 + '0';
  19.     }
  20.   }
  21.   printf(" %s\n", result_s);
  22.   return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement