SHARE
TWEET

[Tablica]Swapowanie liczb w tablicy

Sayukoo Oct 15th, 2019 (edited) 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top