Advertisement
mfgnik

Untitled

Jan 25th, 2021
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include <math.h>
  5. #define N 100
  6.  
  7. void swap(double a[N], int n) {
  8.     int i =0;
  9.     for (i = 0; i + 1 < n; i += 2) {
  10.         double tmp = a[i];
  11.         a[i] = a[i + 1];
  12.         a[i + 1] = tmp;
  13.     }
  14. }
  15.  
  16. int main(){
  17.     double a[N];
  18.     int n, i;
  19.     printf("Input the size of the massiv: ");
  20.     scanf("%d", &n);
  21.     for (i = 0; i < n; i++) {
  22.         printf("a[%d] = ", i);
  23.         scanf("%lg", &a[i]);
  24.     }
  25.     swap(a, n);
  26.  
  27.     for (i = 0; i < n; i++){
  28.         printf("%lg", a[i]);
  29.     }
  30.  
  31.     system("pause");
  32.     return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement