Advertisement
Guest User

2137

a guest
Oct 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 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.         i++;
  29.     }
  30. }
  31.  
  32. void kopiuj (TLiczba skad, TLiczba dokad)
  33. {
  34.     for (int i=0; i < MAX_DL; i++)
  35.     {
  36.         dokad[i]=skad[i];
  37.     }
  38. }
  39.  
  40. void wypisz (TLiczba a)
  41. {
  42.     int dl=MAX_DL -1;
  43.     while (a[dl]==0 && dl>0) dl--;
  44.     //printf ("%d",a[dl]);
  45.     while (dl>=0)
  46.     {
  47.         printf("%d", a[dl]);
  48.         dl --;
  49.     }
  50. }
  51.  
  52. int main()
  53. {
  54.    
  55.     TLiczba  x;
  56.    
  57.     init (x, 1);
  58.    
  59.     for (int i=1; i<=10; i++)
  60.     {
  61.         TLiczba y;
  62.        
  63.         dodaj (x,x,y);
  64.         kopiuj(y,x);
  65.     }
  66.  
  67.     printf("2^10=");
  68.     wypisz (x);
  69.     printf ("\n");
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement