Buscar

ordenaçao de vetores bubble sort

Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original

Ordenação de array com bubble sort
#include <stdio.h>
#include <stdlib.h>
int main()
{
 int qtdIdades;
 int x;
 printf("Quantidade de alunos: \n");
 scanf("%d", &qtdIdades);
 
 int idades[qtdIdades];
 for(x=0; x<qtdIdades; x++)
 {
 printf("Entre com a idade %d:",x);
 scanf("%d", &idades[x]);
 }
 int aux;
 int y;
 for (x=0; x<qtdIdades; x++)
 {
 for(y=x+1 ; y<qtdIdades; y++)
 {
 if (idades[x]> idades[y])
 {
 aux = idades [x];
 idades[x] = idades[y];
 idades[y] = aux;
 }
 }
 }
 printf("**Idades**\n");
 for(x=0; x<qtdIdades; x++)
 {
 printf("idade %d = %d\n",x, idades[x]);
 }
 return 0;
}

Teste o Premium para desbloquear

Aproveite todos os benefícios por 3 dias sem pagar! 😉
Já tem cadastro?

Continue navegando