Advertisement
Guest User

2137

a guest
Oct 21st, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <assert.h>
  3. #include <stdbool.h>
  4. #define MAX_DL 500
  5. #define MAX_W 10
  6.  
  7. typedef int TLiczba[MAX_DL];
  8.  
  9. void init (TLiczba liczba, int wart)
  10. {
  11.     int i=0;
  12.     while (i < MAX_DL)
  13.     {
  14.         liczba [i]=wart%MAX_W;
  15.         wart = wart / MAX_W;
  16.         i++;
  17.     }
  18.     assert(wart==0);
  19. }
  20.  
  21. bool dodaj (TLiczba x, TLiczba y, TLiczba z)
  22. {
  23.     int i=0, temp=0;
  24.     while (i < MAX_DL)
  25.     {
  26.         z[i]=(x[i] + y[i] + temp)%MAX_W;
  27.         temp=(x[i] + y[i] + temp)/MAX_W;
  28.        
  29.         i++;
  30.     }
  31. }
  32.  
  33. void kopiuj (TLiczba skad, TLiczba dokad)
  34. {
  35.     for (int i=0; i < MAX_DL; i++)
  36.     {
  37.         dokad[i]=skad[i];
  38.     }
  39. }
  40.  
  41. void wypisz (TLiczba a)
  42. {
  43.     int dl=MAX_DL -1;
  44.     while (a[dl]==0 && dl>0) dl--;
  45.     //printf ("%d",a[dl]);
  46.     while (dl>=0)
  47.     {
  48.         printf("%d", a[dl]);
  49.         dl --;
  50.     }
  51. }
  52.  
  53. int main()
  54. {
  55.    
  56.     TLiczba  x;
  57.    
  58.     init (x, 1);
  59.    
  60.     for (int i=1; i<=10; i++)
  61.     {
  62.         TLiczba y;
  63.        
  64.         dodaj (x,x,y);
  65.         kopiuj(y,x);
  66.     }
  67.  
  68.     printf("2^10=");
  69.     wypisz (x);
  70.     printf ("\n");
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement