Advertisement
ntamas

listaelemek feltöltése bekéréssel

Feb 3rd, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.   class Program
  9.   {
  10.     static void Main(string[] args)
  11.     {
  12.       List<int> lista = new List<int>();
  13.       int i = 1, a;
  14.       do
  15.       {
  16.         Console.Write("Adja meg a(z) {0}. pozitív számot: ", i++);
  17.         a = Convert.ToInt32(Console.ReadLine());
  18.         if (a != 0)
  19.         {
  20.           lista.Add(a);
  21.         }
  22.       } while (a > 0);
  23.       if(lista.Count > 0)
  24.       {
  25.         Console.WriteLine("A legkisebb szám: {0}", lista.Min());
  26.         Console.WriteLine("A legnagyobb szám: {0}", lista.Max());
  27.         Console.WriteLine("Átlaguk: {0}", (double)lista.Average());
  28.         Console.WriteLine("Összegük: {0}", lista.Sum());
  29.         lista.Sort();
  30.         foreach (int k in lista)
  31.         {
  32.           Console.Write("{0} ", k);
  33.         }
  34.       }
  35.       Console.ReadKey();
  36.     }
  37.   }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement