Advertisement
ppupil2

Q04-PRF192-PE-31.03

Mar 31st, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5.  
  6. void bubblesort (int a[], int size) {
  7.     int i, j;
  8.     int temp;
  9.    
  10.     for (i = size - 1; i > 0; i--) {
  11.         for (j = 0; j < i; j++) {
  12.             if (a[j] < a[j+1]) {
  13.                 temp = a[j];
  14.                 a[j] = a[j+1];
  15.                 a[j+1] = temp;
  16.             }
  17.         }
  18.     }
  19. }
  20.  
  21. int main() {
  22.   system("cls");
  23.   //INPUT - @STUDENT:ADD YOUR CODE FOR INPUT HERE:
  24.     int a[5], b[5];
  25.    
  26.     for (int i = 0; i<5; i++) {
  27.         scanf("%d", &a[i]);
  28.     }
  29.     int j = 0;
  30.     for (int i = 0; i<5; i++) {
  31.         if (a[i] %2 == 1) {
  32.             b[j] = a[i];
  33.             j++;
  34.         }
  35.     }
  36.     bubblesort(b,j);
  37.  
  38.  
  39.  
  40.  
  41.  
  42.   // Fixed Do not edit anything here.
  43.   printf("\nOUTPUT:\n");
  44.   //@STUDENT: WRITE YOUR OUTPUT HERE:
  45.     if (j>0) {
  46.         printf("%d", b[0]);
  47.         if (j>1) {
  48.             for (int i = 1; i<j; i++) {
  49.                 printf(" %d", b[i]);
  50.             }
  51.         }
  52.     }
  53.    
  54.  
  55.  
  56.  
  57.   //--FIXED PART - DO NOT EDIT ANY THINGS HERE
  58.   printf("\n");
  59.   system ("pause");
  60.   return(0);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement