Last active
June 3, 2017 11:09
-
-
Save darkodemic/bdbefa601beddb89ee70f30885979337 to your computer and use it in GitHub Desktop.
Prvi zadatak sa nekog proslog kolokvijuma iz OP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define MAX 10 | |
int sort() { | |
int x[MAX]; | |
int y[MAX]; | |
int brojPromena = 0; | |
int j = 0; //brojac za novi niz y | |
int temp = 0; | |
printf("Unos niza X\n--------------------\n"); | |
// Popunjavanje niza x | |
for (int i = 0; i < MAX; i++) { | |
printf("Unesite %d. element niza X: ", i + 1); | |
scanf("%d", &x[i]); | |
// Kreiranje novog niza y prilikom ucitavanja | |
if (x[i] != 0) { | |
y[j++] = x[i]; | |
} | |
} | |
// Ispis niza x | |
printf("\nUneti niz X: "); | |
for (int i = 0; i < MAX; i++) { | |
printf("%d ", x[i]); | |
} | |
// Ispis niza y | |
printf("\nKreiran niz Y: "); | |
for (int i = 0; i < j; i++) { | |
printf("%d ", y[i]); | |
} | |
//Sortirnje niza y | |
for (int i = 0; i < j; i++) { | |
for (int k = i + 1; k < j; k++) { | |
if (y[i] > y[k]) { | |
temp = y[k]; | |
y[k] = y[i]; | |
y[i] = temp; | |
brojPromena++; | |
} | |
} | |
} | |
// Ispis sortiranog niza y | |
printf("\nSortiran niz y: "); | |
for (int i = 0; i < j; i++) { | |
printf("%d ", y[i]); | |
} | |
return brojPromena; | |
} | |
int main() { | |
int brojPromena = 0; | |
brojPromena = sort(); | |
printf("\nBroj promena prilikom sortiranja niza Y: %d\n", brojPromena); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment