Advertisement
renix1

bubble sort in c

Aug 31st, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int main(void) {
  5.     int idAluno[10] = {0};
  6.     float notaAluno[10] = {0};
  7.  
  8.  
  9.     // Entering the id data
  10.     for (int i=0; i<10; i++) {
  11.         printf("Digite o ID do aluno %d: ", i);
  12.         scanf("%d", &idAluno[i]);
  13.     }
  14.  
  15.     // Entering average
  16.     for (int i=0; i<10; ++i) {
  17.         printf("A nota do aluno %d: ", i);
  18.         scanf("%f", &notaAluno[i]);
  19.     }
  20.  
  21.     // Ordenation algorithm
  22.     for (int i=0; i<10; i++) {
  23.         for (int j=0; j<10-i; j++) {
  24.             if (notaAluno[i] > notaAluno[j]) {
  25.                 float swp_average = notaAluno[i];
  26.                 int swp_id = idAluno[i];
  27.                 notaAluno[i] = notaAluno[j];
  28.                 notaAluno[j] = swp_average;
  29.                 idAluno[i] = idAluno[j];
  30.                 idAluno[j] = swp_id;
  31.             }
  32.         }
  33.     }
  34.  
  35.     // Listing the id
  36.     for (int i=0; i<10; ++i) {
  37.         printf("ID do aluno %d: %d\n", i, idAluno[i]);
  38.     }
  39.  
  40.     // Listing the average
  41.     for (int i=0; i<10; ++i) {
  42.         printf("A nota do aluno %d: %.2f\n", i, notaAluno[i]);
  43.     }
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement