0% found this document useful (0 votes)
17 views

Using Using Using Using Using Namespace Class Static Int New Int Static Int Int

This document defines a C# program that uses an array to store integer values. It defines methods for creating and populating the array, calculating statistics like the average, maximum and minimum values, searching for a given value, and determining if values are prime numbers. The main method displays a menu and calls the appropriate method based on the user's selection, allowing them to perform various operations on the array data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Using Using Using Using Using Namespace Class Static Int New Int Static Int Int

This document defines a C# program that uses an array to store integer values. It defines methods for creating and populating the array, calculating statistics like the average, maximum and minimum values, searching for a given value, and determining if values are prime numbers. The main method displays a menu and calls the appropriate method based on the user's selection, allowing them to perform various operations on the array data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

using System;

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

namespace ConsoleApplication3
{
class Program
{
static int[] A = new int[5]; //declarando el arreglo
static int menu()
{
int opcion;
System.Console.WriteLine("\tArreglo de datos \n\n");
System.Console.WriteLine(" 1 ==>Crear arreglo");
System.Console.WriteLine(" 2 ==>Mostrar arreglo");
System.Console.WriteLine(" 3 ==>Promedio");
System.Console.WriteLine(" 4 ==>Mayor");
System.Console.WriteLine(" 5 ==>Menor");
System.Console.WriteLine(" 6 ==>Buscar");
System.Console.WriteLine(" 7 ==>Suma de positivos");
System.Console.WriteLine(" 8 ==>Suma de negativos");
System.Console.WriteLine(" 9 ==>Numeros primos");
System.Console.WriteLine("¿Que opcion vas a elegir?");
opcion = int.Parse(System.Console.ReadLine());
return opcion;
}

static void creaarreglo()


{
int t;
for (int i = 0; i < 5; i++)// el i++ significa que aumenta de uno en uno
{
System.Console.WriteLine("elemento " + (i + 1));
t = int.Parse(System.Console.ReadLine());
A[i] = t;
System.Console.WriteLine("se ingreso elemento " + (i + 1));
}
System.Console.WriteLine("termino el ingreso de datos");
System.Console.ReadLine();
}
static void mostrararreglo()
{
for (int i = 0; i < 5; i++)
Console.WriteLine("mostrar elemento " + (i + 1) + " " + A[i]);
Console.WriteLine("Termino mostrar arreglo");
System.Console.ReadLine();
}
static void promedio()
{
int suma = 0, prom;
for (int i = 0; i < 5; i++)
{
suma = suma + A[i];
}
prom = suma / 5;
Console.WriteLine("el promedio es " + prom);
System.Console.ReadLine();
}
static void mayor()
{
int mayor;
mayor = A[0];
for (int i = 1; i < 5; i++)
{
if (A[i] > mayor)
mayor = A[i];
}
System.Console.WriteLine("el mayor es " + mayor);
System.Console.ReadLine();
}
static void menor()
{
int menor;
menor = A[0];
for (int i = 1; i < 5; i++)
{
if (A[i] < menor)
menor = A[i];
}
System.Console.WriteLine("el menor es " + menor);
System.Console.ReadLine();
}
static void buscar()
{
int n, i;
bool encontro;
System.Console.WriteLine("¿Que numero desea buscar?");
n = int.Parse(System.Console.ReadLine());
i = 0;
encontro = false;
while (i <= 4 && !encontro)
{
if (n == A[i])
{ encontro = true; }

else
{ i = i + 1; }
}
if (encontro == true)
System.Console.WriteLine("se encunetra en la casilla " + (i + 1));
else
System.Console.WriteLine("no se encontro");

System.Console.ReadLine();
}
static void sumadepositivos()
{
int i = 0, suma = 0;
while (i < 4)
{
if (A[i] > 0)
suma = suma + A[i];
i = i + 1;
}
if (suma == 0)
System.Console.WriteLine("no hay numeros positivos");
else
System.Console.WriteLine("la suma de numeros positivos es " + suma);

}
static void sumadenegativos()
{
int i = 0, suma = 0;
while (i < 4)
{
if (A[i] < 0)
suma = suma + A[i];
i = i + 1;
}
if (suma == 0)
System.Console.WriteLine("no hay numeros negativos");
else
System.Console.WriteLine("la suma de numeros negativos es " + suma);
}
static void numerosprimos()
{
int i, V, C;
i = 0;
V = 2;
C = 0;
while (V < i)
{
if (A[i] % V == 0)
{
C = C + 1;
}
else
V = V + 1;
{
if (C == 0)
System.Console.WriteLine(+(i + 1) + "Es primo");
else
System.Console.WriteLine(+(i + 1) + "no es primo");
}
}
System.Console.ReadLine();

}
static void Main(string[] args)
{
int opc;
opc = menu();
while (opc != 0)
{
switch (opc)
{
case (1): creaarreglo(); break;
case (2): mostrararreglo(); break;
case (3): promedio(); break;
case (4): mayor(); break;
case (5): menor(); break;
case (6): buscar(); break;
case (7): sumadepositivos(); break;
case (8): sumadenegativos(); break;
case (9): numerosprimos(); break;
default: System.Console.WriteLine("error esa opcion no existe");
break;
}
opc = menu();
}
System.Console.WriteLine("salir del menu");
System.Console.ReadLine();
}
}
}

You might also like