Advertisement
dmkozyrev

reverse

Jan 13th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void reverse(int mas[], int N); // Переворот массива
  4. void print(int mas[], int N); // Вывод массива на экран
  5.  
  6. int main(){
  7.     unsigned const int SIZE = 10; // Размер массива
  8.     int a[SIZE]; // Массив
  9.     // Заполнение массива
  10.     int i;
  11.     for(i=0; i < SIZE; i++)
  12.         a[i]=3*i-2;
  13.  
  14.     // Печать изначального массива
  15.     print(a, SIZE);
  16.  
  17.     // Переворот массива
  18.     reverse(a, SIZE);
  19.  
  20.     // Печать измененного массива
  21.     print(a, SIZE);
  22.  
  23.     return 0;
  24. }
  25.  
  26. void reverse(int mas[], int N){
  27.     int i, j;
  28.     for(i = 0, j = N-1; i < j; i++,j--){
  29.         int temp = mas[i];
  30.         mas[i] = mas[j];
  31.         mas[j] = temp;
  32.     }
  33. }
  34.  
  35. void print(int mas[], int N){
  36.     int i;
  37.     for(i = 0; i < N; i++)
  38.         printf("%d ", mas[i]);
  39.     printf("\n");
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement