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. void podzielU( Liczba a, Uint b ) { // a[]:=a[] / b
  32. for( Uint c=0, i=1; i<=N; i++ ) {
  33. c = c*RADIX+a[i];
  34. a[i]= c/b % RADIX;
  35. c = c - a[i]*b;}}
  36.  
  37. void wstawU( Liczba a, Uint b ) { // a[]:= b
  38. Uint i;
  39. for( i=0; i<=N; i++ ) a[i]=0;
  40. i=DP;
  41. while( b ) {
  42. a[i--] = b%RADIX; b /= RADIX; }}
  43.  
  44. void pisz( Liczba a ){ Uint i;
  45. for( i=1; i<=DP && !a[i]; i++ ) printf("%*s", LOG,"");
  46. printf("%*u", LOG, a[i]);
  47. for( i++; i<=DP; i++ ) printf("%0*u", LOG, a[i]);
  48. putchar('.');
  49. for( ; i<=N; i++ ) printf("%0*u", LOG, a[i]); }
  50.  
  51. int main(void) {
  52. Liczba a;
  53. wstawU(a, 12);
  54. razyU(a, 125); pisz(a); puts("");
  55. podzielU(a, 77); pisz(a); puts("");
  56. printf("\n%f\n", 12.0*125/77.0);
  57. return 0;
  58. }
  59.  
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
           1500.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
             19.4805194805194805194805194805194805194805194805194805194805194805194805194805194805194

19.480519