fork download
  1. using static System.Console;
  2.  
  3. namespace exercicio32 {
  4. public class exercicio32 {
  5. public static void Main(string[] args) {
  6. int[] numeros = new int[args.Length];
  7. for (int i = 0; i < args.Length; i++) {
  8. int numero;
  9. if (int.TryParse(args[i], out numero)) numeros[i] = numero;
  10. else WriteLine("Dado inválido! Digite apenas números separados por espaço");
  11. }
  12. Write("Vetor: ");
  13. for (int i = 0; i < args.Length; i++) Write($"{numeros[i]} ");
  14. OrdernaVetor(numeros);
  15. WriteLine("\nVetor Ordenado: ");
  16. for (int i = 0; i < args.Length; i++) Write($"{numeros[i]} ");
  17. }
  18. public static void OrdernaVetor(int[] vetor) {
  19. for (int i = 0; i < vetor.Length; i++) {
  20. for (int j = 0; j < vetor.Length - 1; j++) {
  21. if (vetor[j] > vetor[j + 1]) {
  22. int temp = vetor[j + 1];
  23. vetor[j + 1] = vetor[j];
  24. vetor[j] = temp;
  25. }
  26. }
  27. }
  28. }
  29. }
  30. }
Success #stdin #stdout 0.02s 15972KB
stdin
Standard input is empty
stdout
Vetor: 
Vetor Ordenado: