fork download
  1. #include <stdio.h>
  2.  
  3. typedef unsigned int Uint;
  4. #define N 100
  5. #define DP 1
  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 ) {
  33. c = c*RADIX+a[i];
  34. a[i]= c/RADIX;
  35. c %= RADIX;}}
  36.  
  37. void wstaw( 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. printf("%*u", LOG, a[1]);
  46. for( i=2; i<DP; i++ ) printf("%0*u", LOG, a[i]);
  47. putchar('.');
  48. for( ; i<=N; i++ ) printf("%0*u", LOG, a[i]); }
  49.  
  50. int main(void) {
  51. Liczba
  52. a={0,1,0,9,0}, // 1.09
  53. b={0,2,0,5,1}; // 2.051
  54. plus ( a, b ); pisz(a); puts("");
  55. razyU ( a, 5 ); pisz(a); puts("");
  56. podzielU( a, 3 ); pisz(a); puts("");
  57. return 0;
  58. }
  59.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘podzielU’:
prog.c:32: error: expected ‘;’ before ‘)’ token
stdout
Standard output is empty