SHARE
TWEET

Zadatak 4

a guest Apr 18th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Zadatak 4
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. void swap(int*, int*);
  7.  
  8. int main() {
  9.     int i, j, c;
  10.     int n, k, arr[100];
  11.  
  12.     printf("Unesite velicinu niza: ");
  13.     scanf("%d", &n);
  14.  
  15.     for (i = 0; i < n; i++) {
  16.         printf("Element %d: ", i);
  17.         scanf("%d", &arr[i]);
  18.     }
  19.  
  20.     printf("Koliko najmanjih elementa zelite izbaciti: ");
  21.     scanf("%d", &k);
  22.  
  23.     printf("------------------------------------\n");
  24.     printf("Novi niz:\n[");
  25.  
  26.     for (i = 0; i < n - 1; i++) {
  27.         for (j = 0; j < n - i - 1; j++) {
  28.             if (arr[j] > arr[j + 1]) swap(&arr[j], &arr[j + 1]);
  29.         }
  30.     }
  31.  
  32.     c = 0;
  33.     for (i = k; i < n; i++) {
  34.         printf("%d ", arr[i]);
  35.     }
  36.  
  37.     printf("\b]\n\n");
  38.  
  39.     system("PAUSE");
  40.  
  41.     return 0;
  42. }
  43.  
  44. void swap(int *x, int *y) {
  45.     int temp;
  46.  
  47.     temp = *x;
  48.     *x = *y;
  49.     *y = temp;
  50. }
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