csaki

házimegint

Dec 9th, 2012
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace házimegint
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Console.WriteLine("Válassz a feladatok közül!");
  13.             Console.WriteLine();
  14.             for (int i = 0; i < 10; i++)
  15.             {
  16.                 Console.WriteLine("{0}. feladat", i + 1);
  17.             }
  18.             int menüpont = int.Parse(Console.ReadLine());
  19.  
  20.             // switch
  21.         }
  22.         static Random rand = new Random();
  23.  
  24.         static void feladat1()
  25.         {
  26.             int[] tömb1 = első_feltöltés();
  27.             Console.WriteLine("Melyik számot szeretnéd megszámolni?");
  28.             int keres = int.Parse(Console.ReadLine());
  29.             int hányszor = első_osztómeghatározás(tömb1, keres);
  30.             Console.WriteLine("A keresett szám {0}x szerepel a tömbben.", hányszor);
  31.             Console.ReadLine();
  32.         }
  33.  
  34.         private static int első_osztómeghatározás(int[] tömb1, int keres)
  35.         {
  36.             int hányszor;
  37.             hányszor = 0;
  38.             for (int i = 0; i < tömb1.Length; i++)
  39.             {
  40.                 if (keres == tömb1[i])
  41.                 {
  42.                     hányszor++;
  43.                 }
  44.             }
  45.             return hányszor;
  46.         }
  47.  
  48.         private static int[] első_feltöltés()
  49.         {
  50.             int[] tömb1;
  51.             tömb1 = new int[10];
  52.             for (int i = 0; i < tömb1.Length; i++)
  53.             {
  54.                 tömb1[i] = rand.Next(100);
  55.             }
  56.             return tömb1;
  57.         }
  58.  
  59.         static void feladat2()
  60.         {
  61.             Console.WriteLine("Adjon meg két számot!");
  62.             int egy = int.Parse(Console.ReadLine());
  63.             int kettő = int.Parse(Console.ReadLine());
  64.             int nagyobb = melyik(egy, kettő);
  65.             Console.WriteLine("A nagyobb: " + nagyobb);
  66.             Console.ReadLine();
  67.         }
  68.  
  69.         static int melyik(int a, int b)
  70.         {
  71.             if (a >= b)
  72.             {
  73.                 return a;
  74.             }
  75.  
  76.             return b;
  77.         }
  78.  
  79.         static void feladat3()
  80.         {
  81.             int[] tömb31 = new int[3];
  82.             int[] tömb32 = new int[3];
  83.             int[] tömb33 = new int[3];
  84.             feladat3_feltöltés(tömb31, tömb32, tömb33);
  85.             int ker = kerület(tömb31, tömb32, tömb33);
  86.  
  87.             Console.WriteLine("A legnagyobb háromszög kerülete:" + ker);
  88.         }
  89.  
  90.         private static void feladat3_feltöltés(int[] tömb31, int[] tömb32, int[] tömb33)
  91.         {
  92.             for (int i = 0; i < tömb31.Length; i++)
  93.             {
  94.                 tömb31[i] = rand.Next(100);
  95.                 tömb32[i] = rand.Next(100);
  96.                 tömb33[i] = rand.Next(100);
  97.             }
  98.         }
  99.  
  100.         static int kerület(int[] a, int[] b, int[] c)
  101.         {
  102.             Array.Sort(a);
  103.             Array.Sort(b);
  104.             Array.Sort(c);
  105.  
  106.             int össz = c[c.Length - 1] + b[b.Length - 1] + a[a.Length - 1];
  107.             return össz;
  108.         }
  109.  
  110.         static void feladat4()
  111.         {
  112.             int[] tömb2 = new int[50];
  113.  
  114.             for (int i = 0; i < tömb2.Length; i++)
  115.             {
  116.                 tömb2[i] = rand.Next(1, 500);
  117.             }
  118.             Console.WriteLine("100nál nagyobb páratlan számok: ");
  119.             for (int i = 0; i < tömb2.Length; i++)
  120.             {
  121.                 if (tömb2[i] > 100 && tömb2[i] % 2 == 1)
  122.                 {
  123.                     Console.WriteLine(tömb2[i]);
  124.                 }
  125.             }
  126.  
  127.             Console.WriteLine("3al osztható páros számok: ");
  128.             for (int i = 0; i < tömb2.Length; i++)
  129.             {
  130.                 if (tömb2[i] % 3 == 0 && tömb2[i] % 2 == 0)
  131.                 {
  132.                     Console.WriteLine(tömb2[i]);
  133.                 }
  134.             }
  135.  
  136.             Console.WriteLine("200-300, összeg 5-tel osztható");
  137.             for (int i = 0; i < tömb2.Length; i++)
  138.             {
  139.                 if (tömb2[i] < 200 || tömb2[i] > 300)
  140.                 {
  141.                     string szo1 = tömb2[i].ToString();
  142.                     int szum2 = 0;
  143.                     for (int jobb = 0; jobb < szo1.Length; jobb++)
  144.                     {
  145.                         int a = int.Parse(szo1[jobb].ToString());
  146.                         szum2 += a;
  147.                     }
  148.                     if (szum2 % 5 == 0)
  149.                     {
  150.                         Console.WriteLine(tömb2[i]);
  151.                     }
  152.                 }
  153.             }
  154.  
  155.             Console.WriteLine("100-300, van benne 3as");
  156.             for (int i = 0; i < tömb2.Length; i++)
  157.             {
  158.                 if (100 < tömb2[i] && 300 > tömb2[i])
  159.                 {
  160.                     string szo2 = tömb2[i].ToString();
  161.                     for (int jobb = 0; jobb < szo2.Length; jobb++)
  162.                     {
  163.                         int szam2 = int.Parse(szo2[jobb].ToString());
  164.                         if (szam2 == 3)
  165.                         {
  166.                             Console.WriteLine(tömb2[i]);
  167.                             break;
  168.                         }
  169.                     }
  170.                 }
  171.             }
  172.  
  173.             Console.WriteLine("Legnagyobb 7-tel osztható de 3-mal nem osztható szám");
  174.             int max = int.MinValue;
  175.             for (int i = 0; i < tömb2.Length; i++)
  176.             {
  177.                 if (tömb2[i] % 3 != 0 && tömb2[i] % 7 == 0)
  178.                 {
  179.                     if (tömb2[i] > max)
  180.                     {
  181.                         max = tömb2[i];
  182.                     }
  183.                 }
  184.             }
  185.             if (max == int.MinValue)
  186.             {
  187.                 Console.WriteLine("Nincs ilyen szám!");
  188.             }
  189.             else
  190.             {
  191.                 Console.WriteLine(max);
  192.             }
  193.  
  194.             Console.WriteLine("Szám amiben van 3-as");
  195.             int min = int.MaxValue;
  196.             for (int i = 0; i < tömb2.Length; i++)
  197.             {
  198.                 string szo3 = tömb2[i].ToString();
  199.                 for (int jobb = 0; jobb < szo3.Length; jobb++)
  200.                 {
  201.                     int szam3 = int.Parse(szo3[jobb].ToString());
  202.                     if (szam3 == 3)
  203.                     {
  204.                         if (tömb2[i] < min)
  205.                         {
  206.                             min = tömb2[i];
  207.                         }
  208.                     }
  209.                 }
  210.             }
  211.             if (min == int.MaxValue)
  212.             {
  213.                 Console.WriteLine("Nincs ilyen szám!");
  214.             }
  215.             else
  216.             {
  217.                 Console.WriteLine(min);
  218.             }
  219.             Console.ReadKey();
  220.         }
  221.  
  222.         static void feladat6()
  223.         {
  224.             Console.WriteLine("Totó tippsor: ");
  225.             int egy = 0;
  226.             int ketto = 0;
  227.             int xek = 0;
  228.             string[] toto = new string[14];
  229.  
  230.             int seged = 0;
  231.             while (seged < 14)
  232.             {
  233.                 int szam2 = rand.Next(1, 4);
  234.                 if (szam2 == 1 && egy < 7)
  235.                 {
  236.                     toto[seged] = "1";
  237.                     ketto++;
  238.                     seged++;
  239.                 }
  240.                 if (szam2 == 2 && ketto < 3)
  241.                 {
  242.                     toto[seged] = "2";
  243.                     ketto++;
  244.                     seged++;
  245.                 }
  246.                 if (szam2 == 3 && xek < 4)
  247.                 {
  248.                     toto[seged] = "x";
  249.                     xek++;
  250.                     seged++;
  251.                 }
  252.             }
  253.  
  254.             foreach (string x in toto)
  255.             {
  256.                 Console.Write(x + ", ");
  257.             }
  258.             Console.ReadLine();
  259.         }
  260.  
  261.         static void feladat7()
  262.         {
  263.             int hossz = 5;
  264.             double[] X = new double[hossz];
  265.             for (int i = 0; i < X.Length; i++)
  266.             {
  267.                 X[i] = i + 1;
  268.             }
  269.  
  270.             for (int i = 0; i < X.Length; i++)
  271.             {
  272.                 Console.Write(X[i] + ", ");
  273.             }
  274.  
  275.             Console.WriteLine("\n");
  276.  
  277.             for (int i = 0; i < X.Length; i++)
  278.             {
  279.                 if (i == 0 || i == X.Length - 1)
  280.                 {
  281.                     if (i == 0)
  282.                     {
  283.                         X[i] = (X[i] * i + X[i + 1] * (i + 1)) / 2;
  284.                     }
  285.                     else
  286.                     {
  287.                         X[i] = (X[i - 1] * (i - 1) + X[i] * i) / 2;
  288.                     }
  289.                 }
  290.                 else
  291.                 {
  292.                     X[i] = (X[i - 1] * (i - 1) + X[i] * i + X[i + 1] * (i + 1)) / 3;
  293.                 }
  294.             }
  295.  
  296.             for (int i = 0; i < X.Length; i++)
  297.             {
  298.                 Console.Write((Math.Floor(X[i] * 100)) / 100 + " ; ");
  299.             }
  300.         }
  301.  
  302.         static void feladat9()
  303.         {
  304.             int sorszél = 35;
  305.             int sorhossz = 20;
  306.  
  307.             int[,] bal = new int[sorszél, sorhossz];
  308.             int[,] jobb = new int[sorszél, sorhossz];
  309.  
  310.  
  311.  
  312.             for (int s = 0; s < sorhossz; s++)
  313.             {
  314.                 for (int o = 0; o < sorszél; o++)
  315.                 {
  316.                     bal[o, s] = rand.Next(0, 2);
  317.                     jobb[o, s] = rand.Next(0, 2);
  318.                 }
  319.             }
  320.  
  321.             Console.WriteLine("Színházi ülőhelyek:");
  322.  
  323.  
  324.  
  325.  
  326.             for (int s = 0; s < sorhossz; s++)
  327.             {
  328.                 for (int o = 0; o < sorszél; o++)
  329.                 {
  330.                     if (bal[o, s] == 0)
  331.                     {
  332.  
  333.                         Console.Write(bal[o, s]);
  334.                     }
  335.                     else
  336.                     {
  337.  
  338.                         Console.Write(bal[o, s]);
  339.                     }
  340.                 }
  341.                 Console.Write("\n");
  342.             }
  343.  
  344.  
  345.  
  346.             for (int s = 0; s < sorhossz; s++)
  347.             {
  348.                 Console.SetCursorPosition(sorszél + 2, s + 2);
  349.                 for (int o = 0; o < sorszél; o++)
  350.                 {
  351.                     if (jobb[o, s] == 0)
  352.                     {
  353.                         Console.Write(jobb[o, s]);
  354.                     }
  355.                     else
  356.                     {
  357.                         Console.Write(jobb[o, s]);
  358.                     }
  359.                 }
  360.             }
  361.  
  362.  
  363.             Console.SetCursorPosition(0, sorhossz + 2);
  364.             Console.WriteLine("Bal oldal");
  365.             Console.SetCursorPosition(sorszél + 2, sorhossz + 2);
  366.             Console.WriteLine("Jobb oldal");
  367.             Console.ReadKey();
  368.  
  369.             for (int s = 0; s < sorhossz; s++)
  370.             {
  371.                 for (int o = 0; o < sorszél - 1; o++)
  372.                 {
  373.                     if (bal[o, s] == 0 && bal[o + 1, s] == 0)
  374.                     {
  375.                         Console.SetCursorPosition(o, s + 2);
  376.                         Console.Write("00");
  377.                         Console.ReadKey();
  378.                     }
  379.                 }
  380.             }
  381.  
  382.  
  383.  
  384.             for (int s = 0; s < sorhossz; s++)
  385.             {
  386.                 for (int o = 0; o < sorszél - 1; o++)
  387.                 {
  388.                     if (jobb[o, s] == 0 && jobb[o + 1, s] == 0)
  389.                     {
  390.                         Console.SetCursorPosition(sorszél + 2 + o, s + 2);
  391.                         Console.Write("00");
  392.                         Console.ReadKey();
  393.                     }
  394.                 }
  395.             }
  396.         }
  397.  
  398.         static void feladat10()
  399.         {
  400.             int hossz = 5;
  401.             int min = 1;
  402.             int max = 10;
  403.  
  404.             int[] tomb1 = new int[hossz];
  405.             for (int i = 0; i < tomb1.Length; i++)
  406.             {
  407.                 tomb1[i] = rand.Next(min, max);
  408.             }
  409.  
  410.             int[] tomb2 = new int[hossz];
  411.             for (int i = 0; i < tomb2.Length; i++)
  412.             {
  413.                 tomb2[i] = rand.Next(min, max);
  414.             }
  415.  
  416.             Console.WriteLine("Tömb 1 elemei:");
  417.             for (int i = 0; i < tomb1.Length; i++)
  418.             {
  419.                 Console.Write(tomb1[i] + ", ");
  420.             }
  421.  
  422.             Console.WriteLine("\n\nTömb 2 elemei:");
  423.             for (int i = 0; i < tomb2.Length; i++)
  424.             {
  425.                 Console.Write(tomb2[i] + ", ");
  426.             }
  427.  
  428.  
  429.  
  430.             List<int> kozos_elemek = new List<int>();
  431.  
  432.             for (int t1 = 0; t1 < tomb1.Length; t1++)
  433.             {
  434.                 bool t1_hasznalt = false;
  435.                 for (int k = 0; k < kozos_elemek.Count; k++)
  436.                 {
  437.                     if (tomb1[t1] == kozos_elemek[k])
  438.                     {
  439.                         t1_hasznalt = true;
  440.                         break;
  441.                     }
  442.                 }
  443.  
  444.                 if (t1_hasznalt == false)
  445.                 {
  446.                     for (int t2 = 0; t2 < tomb2.Length; t2++)
  447.                     {
  448.                         if (tomb1[t1] == tomb2[t2])
  449.                         {
  450.                             kozos_elemek.Add(tomb1[t1]);
  451.                             break;
  452.                         }
  453.                     }
  454.                 }
  455.             }
  456.         }
  457.     }
  458. }
Advertisement
Add Comment
Please, Sign In to add comment