Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include<conio.h>
  3. #include<time.h>
  4. #include<stdlib.h>
  5.  
  6. int main(){
  7.  
  8. int polje[25],i,k,j,pom,max,npolje[25]={0},brojac=0;
  9.  
  10. time_t t;
  11. srand((unsigned)time(NULL));
  12.  
  13. printf("Ne sortirano polje\n");
  14.  
  15. k=0;
  16.  
  17. for(i=0;i<25;i++){
  18. polje[i]=10+rand()%(99-10+1);
  19. printf("%d ",polje[i]);
  20. if((polje[i]%2)==0){
  21. npolje[k]=polje[i];
  22. k++;
  23. }
  24. }
  25.  
  26. printf("\nSortirano novo [samo parni] polje\n");
  27.  
  28. for(i=0;i<k;i++)
  29. {
  30. max=i;
  31. for(j=i+1;j<25;j++){
  32. if(npolje[j]>npolje[max])
  33. max=j;
  34. }
  35. pom=npolje[i];
  36. npolje[i]=npolje[max];
  37. npolje[max]=pom;
  38.  
  39. printf(" %d",npolje[i]);
  40.  
  41. }
  42.  
  43. printf("\nSortirano staro polje:\n");
  44. for(i=0;i<25;i++)
  45. {
  46. max=i;
  47. for(j=i+1;j<25;j++){
  48. if(polje[j]>polje[max])
  49. max=j;
  50. }
  51. pom=polje[i];
  52. polje[i]=polje[max];
  53. polje[max]=pom;
  54.  
  55. printf(" %d",polje[i]);
  56.  
  57. }
  58.  
  59.  
  60. getche();
  61. return 0;
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement