Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 1, 2021 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/9e1e6fa097403106188646b780504b0d to your computer and use it in GitHub Desktop.
Save parzibyte/9e1e6fa097403106188646b780504b0d to your computer and use it in GitHub Desktop.
using System;
// https://parzibyte.me/blog
namespace App
{
class Programa
{
static void Main(string[] args)
{
int[] arreglo = { 50, 20, 90, 10, 9 };
Console.WriteLine("Antes de invertir: ");
foreach (var elemento in arreglo)
{
Console.WriteLine(elemento);
}
for (int indiceDelExtremoIzquierdo = 0; indiceDelExtremoIzquierdo < arreglo.Length / 2; indiceDelExtremoIzquierdo++)
{
int indiceDelExtremoDerecho = arreglo.Length - indiceDelExtremoIzquierdo - 1;
int temporal = arreglo[indiceDelExtremoDerecho];
arreglo[indiceDelExtremoDerecho] = arreglo[indiceDelExtremoIzquierdo];
arreglo[indiceDelExtremoIzquierdo] = temporal;
}
Console.WriteLine("Después de invertir: ");
foreach (var elemento in arreglo)
{
Console.WriteLine(elemento);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment