Advertisement
Guest User

Untitled

a guest
May 21st, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. void order(int n, int NUM[]){
  4.  
  5. int ODD[n];
  6. int EVEN[n];
  7.  
  8.  
  9. int eSize = 0;
  10. int oSize = 0;
  11. //---------SORT OUT EVEN AND ODD NUMBERS-----------
  12.  
  13. for(int i = 0; i<n ; i++){
  14.  
  15. if(NUM[i]%2 == 0){
  16. EVEN[eSize] = NUM[i];
  17. eSize++;
  18. }else{
  19. ODD[oSize] = NUM[i];
  20. oSize++;
  21. }
  22. }
  23.  
  24.  
  25. printf("\nOdd numbers : ");
  26. for(int i = 0;i<oSize; i++){
  27. printf("%d ",ODD[i]);
  28. }
  29.  
  30. printf("Even numbers : ");
  31. for(int i = 0;i<eSize; i++){
  32. printf("%d ",EVEN[i]);
  33. }
  34.  
  35.  
  36.  
  37. printf("\n");
  38. //---------SORT IN DECENDING ORDER-----------
  39. for (int i = 0; i < eSize; ++i)
  40. {
  41. for (int j = i + 1; j < eSize; ++j)
  42. {
  43. if (EVEN[i] < EVEN[j])
  44. {
  45. int a = EVEN[i];
  46. EVEN[i] = EVEN[j];
  47. EVEN[j] = a;
  48. }
  49. }
  50. }
  51.  
  52.  
  53. //---------SORT IN ASCENDING ORDER-----------
  54.  
  55. for (int i = 0; i < oSize; i++)
  56. {
  57. for (int j = 0; j < oSize; j++)
  58. {
  59. if (ODD[j] > ODD[i])
  60. {
  61. int tmp = ODD[i];
  62. ODD[i] = ODD[j];
  63. ODD[j] = tmp;
  64. }
  65. }
  66. }
  67.  
  68. //---------PRINT WHOLE ARRAY-----------
  69.  
  70.  
  71. printf("\n\nSorted : ");
  72. for (int i = 0; i < oSize; i++)
  73. {
  74. printf(" %d ", ODD[i]);
  75.  
  76. }
  77.  
  78. for (int i = 0; i < eSize; ++i)
  79. {
  80. printf(" %d ", EVEN[i]);
  81. }
  82.  
  83.  
  84.  
  85.  
  86. }
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101. int main()
  102. {
  103.  
  104. int n = 10;
  105. //2
  106. int NUM[10] = {10,9,6,5,7,8,1,4,3,2};
  107. order(n,NUM);
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement