Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define MAXLENGTH 25
  6.  
  7. int main(){
  8.     int a=10, b=99, i, j, k, z=0;
  9.     int pom, max;
  10.     int polje[MAXLENGTH]={0}, novo[MAXLENGTH]={0};
  11.  
  12.     srand((unsigned)time(0));
  13.     for (i=0; i<MAXLENGTH; i++){
  14.         polje[i] = a + rand() % (b - a + 1);
  15.     }
  16.  
  17.     printf("Prvo polje:\n");
  18.     for (i=0; i<MAXLENGTH; i++){
  19.         printf("%d ", polje[i]);
  20.     }
  21.     printf("\n\n");
  22.  
  23.     for(i=0; i<MAXLENGTH-1; i++){
  24.         max = i;
  25.         for (j=i+1; j<MAXLENGTH; j++)
  26.             if (polje[j] > polje[max])
  27.                 max = j;
  28.                 pom = polje[i];
  29.                 polje[i]=polje[max];
  30.                 polje[max]=pom;
  31.     }
  32.            
  33.     printf("Silazno sortirano polje je:\n");
  34.     for(i=0; i<MAXLENGTH; i++){
  35.         printf("%d ", polje[i]);
  36.     }
  37.     printf("\n\n");
  38.  
  39.     for(i=0; i<MAXLENGTH; i++){
  40.         if (polje[i] %2 != 0){
  41.             novo[z]=polje[i];
  42.             z++;
  43.         }
  44.     }
  45.  
  46.     printf("Ima %d neparnih clanova polja a to su:\n", z);
  47.     for(i=0; i<z; i++){
  48.         printf("%d ", novo[i]);
  49.     }
  50.     printf("\n\n");
  51.  
  52.     system("pause");
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement