Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, const char * argv[]) {
- int n;
- scanf("%d", &n);
- int niza[n];
- for(int i = 0; i < n; i++) {
- scanf("%d", &niza[i]);
- }
- for(int i = 0; i < n - 1; i++) {
- int broj_na_deliteli1 = 0;
- for(int j = 1; j <= niza[i]; j++) {
- if(niza[i] % j == 0) {
- broj_na_deliteli1++;
- }
- }
- int broj_na_deliteli2 = 0;
- for(int j = 1; j <= niza[i + 1]; j++) {
- if(niza[i + 1] % j == 0) {
- broj_na_deliteli2++;
- }
- }
- if(broj_na_deliteli1 == 2 && broj_na_deliteli2 == 2) {
- int pom = niza[i];
- niza[i] = niza[i + 1];
- niza[i + 1] = pom;
- i++;
- }
- }
- for(int i = 0; i < n; i++) {
- printf("%d ", niza[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement