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 plus( Liczba a, Liczba b){ // a[]:=a[]+b[]
  12. for( Uint c=0, i=N; i>0; i-- ){
  13. c += a[i]+b[i];
  14. a[i] = c % RADIX;
  15. c /= RADIX;}}
  16.  
  17. void minus( Liczba a, Liczba b ) { // a[]:=a[]-b[]
  18. for( Uint c=0, i=N; i>0; i-- ){
  19. c += b[i];
  20. if( a[i]<c ){
  21. a[i] = RADIX + a[i] - c; c=1; }
  22. else {
  23. a[i] -= c; c=0; }}}
  24.  
  25. void razyU( Liczba a, Uint b ) { // a[]:=a[] * b
  26. for( Uint c=0,i=N; i>0; i-- ){
  27. c += a[i]*b;
  28. a[i]= c % RADIX;
  29. c /= RADIX; }}
  30.  
  31. int podzielU( Liczba a, Uint b ) { // a[]:=a[] / b
  32. Uint z=0;
  33. for( Uint c=0, i=1; i<=N; i++ ) {
  34. c = c*RADIX+a[i];
  35. a[i]= c/b % RADIX; if( a[i] ) z=1;
  36. c = c - a[i]*b;}
  37. return z;}
  38.  
  39. void wstawU( Liczba a, Uint b ) { // a[]:= b
  40. Uint i;
  41. for( i=0; i<=N; i++ ) a[i]=0;
  42. i=DP;
  43. while( b ) {
  44. a[i--] = b%RADIX; b /= RADIX; }}
  45.  
  46. void atan( Liczba a, Uint x ) { // a[]:= atan( 1/x )
  47. Liczba w; Uint z, n=3;
  48. wstawU( w, 1 ); wstawU( a, 1 ); podzielU(a, x);
  49. do {
  50. x *= x*x; z=podzielU( w, x*n ); n += 2;minus( a, w );
  51. x *= x*x; z=podzielU( w, x*n ); n += 2; plus( a, w );
  52. } while( z );}
  53.  
  54. void pisz( Liczba a ){ Uint i;
  55. for( i=1; i<=DP && !a[i]; i++ ) printf("%*s", LOG,"");
  56. printf("%*u", LOG, a[i]);
  57. for( i++; i<=DP; i++ ) printf("%0*u", LOG, a[i]);
  58. putchar('.');
  59. for( ; i<=N; i++ ) printf("%0*u", LOG, a[i]); }
  60.  
  61. int main(void) {
  62. Liczba a;
  63. wstawU(a, 12);
  64. razyU(a, 125); pisz(a); puts("");
  65. podzielU(a, 77); pisz(a); puts("");
  66. printf("\n%0.14f\n", 12.0*125/77.0);
  67. return 0;
  68. }
  69.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
cc1: warnings being treated as errors
prog.c:46: error: conflicting types for built-in function ‘atan’
stdout
Standard output is empty