Advertisement
Josif_tepe

Untitled

Aug 22nd, 2023
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(int argc, const char * argv[]) {
  4.     int n;
  5.     scanf("%d", &n);
  6.     int niza[n];
  7.     for(int i = 0; i < n; i++) {
  8.         scanf("%d", &niza[i]);
  9.        
  10.     }
  11.    
  12.     for(int i = 0; i < n - 1; i++) {
  13.         int broj_na_deliteli1 = 0;
  14.        
  15.         for(int j = 1; j <= niza[i]; j++) {
  16.             if(niza[i] % j == 0) {
  17.                 broj_na_deliteli1++;
  18.             }
  19.         }
  20.         int broj_na_deliteli2 = 0;
  21.         for(int j = 1; j <= niza[i + 1]; j++) {
  22.             if(niza[i + 1] % j == 0) {
  23.                 broj_na_deliteli2++;
  24.             }
  25.         }
  26.         if(broj_na_deliteli1 == 2 && broj_na_deliteli2 == 2) {
  27.             int pom = niza[i];
  28.             niza[i] = niza[i + 1];
  29.             niza[i + 1] = pom;
  30.            
  31.             i++;
  32.         }
  33.     }
  34.     for(int i = 0; i < n; i++) {
  35.         printf("%d ", niza[i]);
  36.     }
  37.     return 0;
  38.    
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement