Вы находитесь на странице: 1из 6

Ejercicios trabajados en clase

1.EN ORDEN CRECIENTE


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
class Program
{
static void MostrarVector (ref int []v)
{
int i;
for (i=0;i<v.Length;i=i+1)
{
Console.WriteLine(v[i]);
}
}
static void Main(string[] args)
{
int[] A = new int[] { 12, 90, 78, 34, 90, 120, 34, 54, 12, 21 };
int N = A.Length;
int i, j;
int aux;
Console.WriteLine("Vector inicial");
MostrarVector(ref A);
//codigo de ordenamiento
for (i = 0; i < N - 1; i = i + 1)
{
for (j = i + 1; j < N; j = j + 1)
{
if (A[i] > A[j])
{
//intercambio de valores
aux = A[i];
A[i] = A[j];
A[j] = aux;
}
}
}
Console.WriteLine("Vector Ordenado Creciente: ");
MostrarVector(ref A);
Console.ReadKey();

}
}
}
2. En orden decreciente

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
class Program
{
static void MostrarVector (ref int []v)
{
int i;
for (i=0;i<v.Length;i=i+1)
{
Console.WriteLine(v[i]);
}
}
static void Main(string[] args)
{
int[] A = new int[] { 12, 90, 78, 34, 90, 120, 34, 54, 12, 21 };
int N = A.Length;
int i, j;
int aux;
Console.WriteLine("Vector inicial");
MostrarVector(ref A);
//codigo de ordenamiento
for (i = 0; i < N - 1; i = i + 1)
{
for (j = i + 1; j < N; j = j + 1)
{
if (A[i] < A[j])
{
//intercambio de valores
aux = A[i];
A[i] = A[j];
A[j] = aux;
}
}
}
Console.WriteLine("Vector Ordenado Creciente: ");
MostrarVector(ref A);
Console.ReadKey();

}
}
}

3. ORDENAMIENTO CON NOMBRES


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
class Program
{
static void MostrarVector (ref string []v1 ,ref int []v2)
{
int i;
for (i=0;i<v1.Length;i=i+1)
{
Console.WriteLine("{0} \t {1}",v1[i],v2[i]);
}
}
static void Main(string[] args)
{
int[] vnotas= new int[] { 12,9,7,4,19,20,3,5,12,20};
string[] vnombres = new string[] { "carlos", "rosa", "luis", "ana",
"carmen", "oscar", "miura", "andre","jorge","tania" };
int N = vnotas.Length;
int i, j;
int aux;
string auxs;
Console.WriteLine("Vector al inicio");
MostrarVector(ref vnombres ,ref vnotas);
//codigo de ordenamiento
for (i = 0; i < N - 1; i = i + 1)
{
for (j = i + 1; j < N; j = j + 1)
{
if (vnotas[i] > vnotas[j])
{
//intercambio de valores
aux = vnotas[i];
vnotas[i] = vnotas[j];
vnotas[j] = aux;
//intercambio de vnombres en las posiciones i y j
auxs = vnombres[i];
vnombres[i] = vnombres[j];
vnombres[j] = auxs;
}
}
}
Console.WriteLine("Vector al inicio: ");
MostrarVector(ref vnombres , ref vnotas );
Console.WriteLine("Vectores Ordenado Creciente");
Console.ReadKey();

}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
class Program
{
static void MostrarVector (ref string []v1 ,ref int []v2)
{
int i;
for (i=0;i<v1.Length;i=i+1)
{
Console.WriteLine("{0} \t {1}",v1[i],v2[i]);
}
}
static void MostrarVectorPart1 (ref string[]v1,ref int[]v2,int p)
{
int i;
for(i=0;i<p;i=i+1)
{
Console.WriteLine("{0} \t {1}", v1[i], v2[i]);
}
}
static void MostrarVectorPart2(ref string[] v1, ref int[] v2, int p)
{
int i;
int n = v1.Length;
for (i = n-p; i < n; i = i + 1)
{
Console.WriteLine("{0} \t {1}", v1[i], v2[i]);
}
}

static void Main(string[] args)


{
int[] vnotas = new int[] { 12, 9, 7, 4, 19, 20, 3, 5, 12, 20 };
string[] vnombres = new string[] { "carlos", "rosa", "luis", "ana",
"carmen", "oscar", "miura", "andre", "jorge", "tania" };
int N = vnotas.Length;
int i, j;
int aux;
string auxs;
Console.WriteLine("Vector al inicio");
MostrarVector(ref vnombres, ref vnotas);
//codigo de ordenamiento
for (i = 0; i < N - 1; i = i + 1)
{
for (j = i + 1; j < N; j = j + 1)
{
if (vnotas[i] > vnotas[j])
{
//intercambio de valores
aux = vnotas[i];
vnotas[i] = vnotas[j];
vnotas[j] = aux;
//intercambio de vnombres en las posiciones i y j
auxs = vnombres[i];
vnombres[i] = vnombres[j];
vnombres[j] = auxs;
}
}
}
Console.WriteLine("Vector al inicio: ");
MostrarVector(ref vnombres, ref vnotas);
Console.WriteLine("Vectores Ordenado Creciente");
//LAS TRES NOTAS MAS BAJAS
Console.WriteLine("\n Las notas mas bajas son: ");
for(int B=0;B<=2;B=B+1)
{
Console.WriteLine("{0} \t {1}", vnombres[B], vnotas[B]);
}
//las tres notas mas altas
Console.WriteLine("\n Las notas mas altas son: ");
for (int B = 7; B <= 9; B = B + 1)
{
Console.WriteLine("{0} \t {1}", vnombres[B], vnotas[B]);
}
Console.ReadKey();
}
}
}

Вам также может понравиться