Advertisement
Guest User

odw

a guest
Jun 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>
  5.  
  6. int main ()
  7. {
  8.     int size = 15;
  9.     int i,j,tab[size],losowa, temp;
  10.    
  11.     srand(time(NULL));
  12.    
  13.     //wypełnienie
  14.     for(i=0; i<size; i++)
  15.     {
  16.         tab[i] = rand()%10;
  17.     }
  18.  
  19.     //wypełnienie przed odwracaniem
  20.     for(i=0; i<size; i++)
  21.     {
  22.         printf("%d",tab[i]);
  23.     }
  24.  
  25.     //odwracanie z pomocą zmiennej tymczasowej (size/2 ponieważ nie chcemy odwrócić jej dwa razy - wystarczy dojście z tym do połowy)
  26.     for(i=0; i<size/2; i++)
  27.     {
  28.         temp = tab[i];
  29.         tab[i] = tab[1000 - i];
  30.         tab[1000-i] = temp;
  31.     }
  32.  
  33.     //wypisanie po odwracaniu
  34.     for(i=0; i<size; i++)
  35.     {
  36.         printf("%d",tab[i]);
  37.     }
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement