Version:1.0 StartHTML:000000259 EndHTML:000024188 StartFragment:000019195 EndFragment:000024072 StartSelection:000019195 EndSelection:000024072 SourceURL:https://forum.imasters.com.br/topic/290531-resolvido%C2%A0vetor-para-colocar-em-ordem-crescente/[Resolvido] Vetor para colocar em ordem crescente - C/C++ - Fórum iMasters
1. Desenvolva um programa que receba 10 números, guarde em uma array e depois mostre em ordem crescente.
#include <stdlib.h>
#include <stdio.h>
int main()
{
int x[10];
int i, j, temp;
/* Leitura do Vetor */
for (i = 0; i<10; i++)
{
printf("Digite um numero:");
scanf("%d",&x[i]);
}
//ordenando o vetor
for (i=0;i<10; i++)
for(j=i+1;j<10;j++)
{
if (x[i]>x[j])
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
/* Impressão do Vetor Ordenado */
printf("Vetor em ordem crescente: \n");
for(i=0;i<10;i++)
printf(" %d",x[i]);
system("pause");
return 0;
}
#include <stdlib.h>
#include <stdio.h>
int main()
{
int x[10];
int i, j, temp;
/* Leitura do Vetor */
for (i = 0; i<10; i++)
{
printf("Digite um numero:");
scanf("%d",&x[i]);
}
//ordenando o vetor
for (i=0;i<10; i++)
for(j=i+1;j<10;j++)
{
if (x[i]>x[j])
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
/* Impressão do Vetor Ordenado */
printf("Vetor em ordem crescente: \n");
for(i=0;i<10;i++)
printf(" %d",x[i]);
system("pause");
return 0;
}
Para escrever sua resposta aqui, entre ou crie uma conta.
Linguagem de Programação Estruturada
•UNIP
Compartilhar