Advertisement
Sayukoo

[Tablica]Swapowanie liczb w tablicy

Oct 15th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int n,i,*x,tymczasowa;
  4. int main()
  5. {
  6. //Zadanie 4 Zmienić kolejność elementów w tablicy na odwrót.
  7.  
  8.  
  9.   printf("Podaj Ilosc elementow tablicy ktore chcesz: ");
  10.   scanf("%d",&n);
  11.   x = (int*) malloc (n+1 * sizeof(int));
  12.     for(i=0;i<n;i++)
  13.     {
  14.         printf("%d element tablicy to : ",i+1);    scanf("%d",&x[i+1]);
  15.     }
  16.  
  17.     for(int i=1;i<=n/2;i++)
  18.     {
  19.          tymczasowa=x[i];
  20.         x[i]=x[n-i];
  21.         x[n-i]=tymczasowa;
  22.     }
  23. ///   temp=a
  24. ///   a=b
  25. ///   b=temp
  26.     for(int i=0;i<n;i++)
  27.         printf("%d ",x[i+1]);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement