Advertisement
ntamas

struktúra + lista

Feb 17th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 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.     public struct varosok
  11.     {
  12.       public string varos;
  13.       public int homerseklet;
  14.     }
  15.     static void Main(string[] args)
  16.     {
  17.       List<varosok> lista = new List<varosok>();
  18.       varosok varos = new varosok();
  19.       string[] varostomb = new string[5] { "Miskolc", "Debrecen", "Zalaegerszeg", "Budapest", "Eger"};
  20.       int[] hotomb = new int[5] { -6, -15, -4, 10, 5};
  21.       for (int i = 0; i < varostomb.Length; i++ )
  22.       {
  23.         varos.varos = varostomb[i];
  24.         varos.homerseklet = hotomb[i];
  25.         lista.Add(varos);
  26.       }
  27.       int min = 0, max = 0;
  28.       for (int i = 0; i < lista.Count; i++ )
  29.       {
  30.         Console.WriteLine("{0} {1}", lista[i].varos, lista[i].homerseklet);
  31.       }
  32.       for (int j = 0; j < lista.Count; j++ )
  33.       {
  34.         if (lista[j].homerseklet < lista[min].homerseklet)
  35.         {
  36.           min = j;
  37.         }
  38.         else if (lista[j].homerseklet > lista[max].homerseklet)
  39.         {
  40.           max = j;
  41.         }
  42.       }
  43.       Console.WriteLine("A leghidegebb város: {0}", lista[min].varos);
  44.       Console.WriteLine("A legmelegebb város: {0}", lista[max].varos);
  45.       Console.WriteLine("A minimum hőmérséklet: {0}", hotomb.Min());
  46.       Console.WriteLine("A maximum hőmérséklet: {0}", hotomb.Max());
  47.       Console.WriteLine("A hőmérsékletek átlaga: {0}", (double)hotomb.Average());
  48.       Console.ReadKey();
  49.     }
  50.   }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement