Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.Linq;
- using System.Text;
- namespace ejercicio4
- {
- class Program
- {
- static void Main(string[] args)
- {
- ArrayList array = new ArrayList();
- int num;
- char resp;
- bool validar;
- do
- {
- do
- {
- Console.WriteLine("Ingrese un numero: ");
- validar = Int32.TryParse(Console.ReadLine(), out num);
- if (!validar)
- Console.WriteLine("Ops, intentelo de nuevo");
- } while (!validar);
- array.Add(num);
- Console.WriteLine("Seguir ingresando? s/n");
- resp = char.Parse(Console.ReadLine());
- }while (resp != 'n'&&resp != 'N');
- Console.Clear();
- mostrar(array);
- Console.WriteLine("El promedio es {0}", Math.Truncate(promedio(array)*100)/100);
- Console.WriteLine("Hay {0} numero/s menor/es al promedio", menores(array));
- Console.ReadKey();
- }
- static double promedio(ArrayList a)
- {
- double sum = 0;
- foreach (int n in a)
- sum = sum + n;
- return (sum / a.Count);
- }
- static int menores(ArrayList b)
- {
- int min = 0;
- foreach (int n in b)
- if (n < promedio(b))
- min = min + 1;
- return min;
- }
- static void mostrar(ArrayList c)
- {
- Console.WriteLine("Numeros ingresados: ");
- foreach (int n in c)
- Console.WriteLine(n);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement