Está en la página 1de 10

1- Progama que el usuario seleccione el tamaño del vector y muestre el numero

mayor

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

namespace Numero_mayor
{
class Program
{
static void Main(string[] args)
{
int[] vector;
int tam, pos;
//Entrada//
tam = Pedir_Tamaño();
vector = new int[tam];
Llenar_datos(vector);
//Proceso//
pos = Buscar_Posicion_Mayor(vector);
//SALIDA//
Mostrar_Resultados(vector, pos);
Console.ReadKey();

static int Pedir_Tamaño() //Devuelve Datos


{
int tam;
Console.WriteLine("Introduce el tamño del Vector: ");
tam = int.Parse(Console.ReadLine());
return tam;

static void Llenar_datos(int[] vector)


{
for (int i = 0; i <= vector.GetUpperBound(0); i++)
{
Console.Write("\tintroduce el dato {0}", i + 1);
vector[i] = int.Parse(Console.ReadLine());
}

}
static int Buscar_Posicion_Mayor(int[] vector)
{
int posMayor = 0;

for (int i = 0; i <= vector.GetUpperBound(0); i++)


{
if (vector[i] > vector[posMayor])
{
posMayor = i;
}
}
return posMayor;
}
static void Mostrar_Resultados(int[] vector, int pos)
{
Console.WriteLine("\n\n\t los resultados son");
for (int i = 0; i <= vector.GetUpperBound(0); i++)

{
Console.WriteLine("\t{0}", vector[i]);
}
Console.WriteLine("\n\t el numero mayor es {0} y esta en la posicion
{0}", vector[pos], pos + 1);
Console.ReadKey();
}
}
}
2- Progama que el usuario seleccione el tamaño del vector y muestre el numero
menor

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

namespace Numero_mayor
{
class Program
{
static void Main(string[] args)
{
int[] vector;
int tam, pos;
//Entrada//
tam = Pedir_Tamaño();
vector = new int[tam];
Llenar_datos(vector);
//Proceso//
pos = Buscar_Posicion_Menor(vector);
//SALIDA//
Mostrar_Resultados(vector, pos);
Console.ReadKey();

static int Pedir_Tamaño() //Devuelve Datos


{
int tam;
Console.WriteLine("Introduce el tamño del Vector: ");
tam = int.Parse(Console.ReadLine());
return tam;

static void Llenar_datos(int[] vector)


{
for (int i = 0; i <= vector.GetUpperBound(0); i++)
{
Console.Write("\tintroduce el dato {0}", i + 1);
vector[i] = int.Parse(Console.ReadLine());
}

}
static int Buscar_Posicion_Menor(int[] vector)
{
int posMenor = 0;

for (int i = 0; i <= vector.GetUpperBound(0); i++)


{
if (vector[i] < vector[posMenor])
{
posMenor = i;
}

}
return posMenor;
}
static void Mostrar_Resultados(int[] vector, int pos)
{
Console.WriteLine("\n\n\t los resultados son");
for (int i = 0; i <= vector.GetUpperBound(0); i++)

{
Console.WriteLine("\t{0}", vector[i]);
}
Console.WriteLine("\n\t el numero menor es {0} y esta en la posicion
{0}", vector[pos], pos + 1);
Console.ReadKey();
}
}
}

3 – programa que muestre una matriz de 4 x 4 y sume las diagonales y muestre el promedio

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[,] tabla = new int[4, 4];
int cont1 = 0;
int cont2 = 0;
int suma = 0;
double prom = 0;
Console.WriteLine("********* MATRIZ 4X4 *********");

for (cont1 = 0; cont1 < 4; cont1++)


{
for (cont2 = 0; cont2 < 4; cont2++)
{
Console.WriteLine("dame el valor de la pósicion " + cont1 + ","
+ cont2 + " de la matriz ");
tabla[cont1, cont2] = int.Parse(Console.ReadLine());
}
}

for (cont1 = 0; cont1 < 4; cont1++)


{
for (cont2 = 0; cont2 < 4; cont2++)
{
if (cont1 == cont2 | (cont1 + cont2) == 3)
{
suma = suma + tabla[cont1, cont2];
}

}
}

prom = suma / 8;

for (cont1 = 0; cont1 < 4; cont1++)


{
for (cont2 = 0; cont2 < 4; cont2++)
{
Console.Write(tabla[cont1, cont2] + " ");

}
Console.ReadLine();
}

Console.WriteLine("la suma de las dos diagonales es " + suma);


Console.WriteLine("el promedio de las diagonales es " + prom);

Console.ReadLine();
}
}
}

4 – programa de una matriz 4 x 4

Que el usuario de num 1 en las diagonales

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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[,] tabla = new int[5, 5];
int suma = 0;
for (int col = 0; col <= 4; col++)
{
for (int fila = 0; fila <= 4; fila++)
{
suma = col + fila;
if (suma == 4)
{
Console.Write("\t1");
}
else
{
Console.Write("\t0");
}
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
5- crar un matriz de 4 x 4 dado por el usuario como la anterior pero la diagonal con valor sea
inversa

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

class Program

static void Main(string[] args)

int[,] tabla = new int [5,5];

for (int col = 0; col <= 4; col++)

for (int fila = 0; fila <= 4; fila++)

if (fila== col)

Console.Write("\t1");

else
{

Console.Write("\t0");

Console.WriteLine();

Console.ReadLine();

6- hacer u programa que dado introducir 10 numeros los muestre en orden normal y después al
inverso

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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] numero = new int[10];

Console.WriteLine("Ingresa los numeros que deseas");

for (int i = 0; i <= numero.GetUpperBound(0); i++)


{
Console.Write("Introduce el dato {0}: ", i + 1);
numero[i] = int.Parse(Console.ReadLine());
}

Console.WriteLine("Para ver los numeros, presiona 'Enter'");


Console.ReadLine();

for (int i = 0; i <= 9; i++)


{
Console.WriteLine(numero[i]);

Console.ReadLine();

Console.WriteLine("\n Al inverso");

for (int i = numero.Length - 1; i >= 0; i--)


{
Console.WriteLine(numero[i]);

Array.Reverse(numero);

Console.ReadLine();

}
}
}

También podría gustarte