Advertisement
Guest User

Untitled

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