fork download
  1. #include <stdio.h>
  2.  
  3. typedef unsigned int Uint;
  4. #define N 100
  5. #define DP 15
  6. //RADIX == 10^LOG
  7. #define LOG 1
  8. #define RADIX 10
  9. typedef Uint Liczba[N+1];
  10.  
  11. void pisz( Liczba a ){ Uint i;
  12. for( i=1; i<=DP && !a[i]; i++ ) printf("%*s", LOG,"");
  13. printf("%*u", LOG, a[i]);
  14. for( i++; i<=DP; i++ ) printf("%0*u", LOG, a[i]);
  15. putchar('.');
  16. for( ; i<=N; i++ ) printf("%0*u", LOG, a[i]); }
  17.  
  18. void plus( Liczba a, Liczba b){ // a[]:=a[]+b[]
  19. for( Uint c=0, i=N; i>0; i-- ){
  20. c += a[i]+b[i];
  21. a[i] = c % RADIX;
  22. c /= RADIX;}}
  23.  
  24. void minus( Liczba a, Liczba b ) { // a[]:=a[]-b[]
  25. for( Uint c=0, i=N; i>0; i-- ){
  26. c += b[i];
  27. if( a[i]<c ){
  28. a[i] = RADIX + a[i] - c; c=1; }
  29. else {
  30. a[i] -= c; c=0; }}}
  31.  
  32. void razyU( Liczba a, Uint b ) { // a[]:=a[] * b
  33. for( Uint c=0,i=N; i>0; i-- ){
  34. c += a[i]*b;
  35. a[i]= c % RADIX;
  36. c /= RADIX; }}
  37.  
  38. int podzielU( Liczba a, Uint b ) { // a[]:=a[] / b
  39. Uint z=0;
  40. for( Uint c=0, i=1; i<=N; i++ ) {
  41. c = c*RADIX+a[i];
  42. a[i]= c/b % RADIX; if( a[i] ) z=1;
  43. c = c - a[i]*b;}
  44. return z;}
  45.  
  46. void wstawU( Liczba a, Uint b ) { // a[]:= b
  47. Uint i;
  48. for( i=0; i<=N; i++ ) a[i]=0;
  49. i=DP;
  50. while( b ) {
  51. a[i--] = b%RADIX; b /= RADIX; }}
  52.  
  53. void atg( Liczba a, Uint x ) { // a[]:= atan( 1/x )
  54. Liczba w; Uint z, n=3;
  55. wstawU( w, 1 ); wstawU( a, 1 ); podzielU(a, x);
  56. do {
  57. x *= x*x; z=podzielU( w, x*n ); n += 2;minus( a, w );
  58. x *= x*x; z=podzielU( w, x*n ); n += 2; plus( a, w );
  59. pisz(w); puts("");
  60. } while( z );}
  61.  
  62. int main(void) {
  63. Liczba a;
  64. wstawU(a, 12);
  65. razyU(a, 125); pisz(a); puts("");
  66. podzielU(a, 77); pisz(a); puts("");
  67. atg(a, 5);pisz(a); puts("");
  68. printf("\n%0.14f\n", 12.0*125/77.0);
  69. return 0;
  70. }
  71.  
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
           1500.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
             19.4805194805194805194805194805194805194805194805194805194805194805194805194805194805194
               0.000000002730666666666666666666666666666666666666666666666666666666666666666666666666
               0.000000000000000000000000000000000000001000000000000000000000010001000100000000100000
               0.000000000000000000000000000000000000000000000000000000000010011011110001000001001100
               0.000000000000000000000000000000000000000000000000000000000000000000000000000010001210
               0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000
               1.973333336063999999999998989999989899900999999998886998887788809910881552075844988609

19.48051948051948