Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace házimegint
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Válassz a feladatok közül!");
- Console.WriteLine();
- for (int i = 0; i < 10; i++)
- {
- Console.WriteLine("{0}. feladat", i + 1);
- }
- int menüpont = int.Parse(Console.ReadLine());
- // switch
- }
- static Random rand = new Random();
- static void feladat1()
- {
- int[] tömb1 = első_feltöltés();
- Console.WriteLine("Melyik számot szeretnéd megszámolni?");
- int keres = int.Parse(Console.ReadLine());
- int hányszor = első_osztómeghatározás(tömb1, keres);
- Console.WriteLine("A keresett szám {0}x szerepel a tömbben.", hányszor);
- Console.ReadLine();
- }
- private static int első_osztómeghatározás(int[] tömb1, int keres)
- {
- int hányszor;
- hányszor = 0;
- for (int i = 0; i < tömb1.Length; i++)
- {
- if (keres == tömb1[i])
- {
- hányszor++;
- }
- }
- return hányszor;
- }
- private static int[] első_feltöltés()
- {
- int[] tömb1;
- tömb1 = new int[10];
- for (int i = 0; i < tömb1.Length; i++)
- {
- tömb1[i] = rand.Next(100);
- }
- return tömb1;
- }
- static void feladat2()
- {
- Console.WriteLine("Adjon meg két számot!");
- int egy = int.Parse(Console.ReadLine());
- int kettő = int.Parse(Console.ReadLine());
- int nagyobb = melyik(egy, kettő);
- Console.WriteLine("A nagyobb: " + nagyobb);
- Console.ReadLine();
- }
- static int melyik(int a, int b)
- {
- if (a >= b)
- {
- return a;
- }
- return b;
- }
- static void feladat3()
- {
- int[] tömb31 = new int[3];
- int[] tömb32 = new int[3];
- int[] tömb33 = new int[3];
- feladat3_feltöltés(tömb31, tömb32, tömb33);
- int ker = kerület(tömb31, tömb32, tömb33);
- Console.WriteLine("A legnagyobb háromszög kerülete:" + ker);
- }
- private static void feladat3_feltöltés(int[] tömb31, int[] tömb32, int[] tömb33)
- {
- for (int i = 0; i < tömb31.Length; i++)
- {
- tömb31[i] = rand.Next(100);
- tömb32[i] = rand.Next(100);
- tömb33[i] = rand.Next(100);
- }
- }
- static int kerület(int[] a, int[] b, int[] c)
- {
- Array.Sort(a);
- Array.Sort(b);
- Array.Sort(c);
- int össz = c[c.Length - 1] + b[b.Length - 1] + a[a.Length - 1];
- return össz;
- }
- static void feladat4()
- {
- int[] tömb2 = new int[50];
- for (int i = 0; i < tömb2.Length; i++)
- {
- tömb2[i] = rand.Next(1, 500);
- }
- Console.WriteLine("100nál nagyobb páratlan számok: ");
- for (int i = 0; i < tömb2.Length; i++)
- {
- if (tömb2[i] > 100 && tömb2[i] % 2 == 1)
- {
- Console.WriteLine(tömb2[i]);
- }
- }
- Console.WriteLine("3al osztható páros számok: ");
- for (int i = 0; i < tömb2.Length; i++)
- {
- if (tömb2[i] % 3 == 0 && tömb2[i] % 2 == 0)
- {
- Console.WriteLine(tömb2[i]);
- }
- }
- Console.WriteLine("200-300, összeg 5-tel osztható");
- for (int i = 0; i < tömb2.Length; i++)
- {
- if (tömb2[i] < 200 || tömb2[i] > 300)
- {
- string szo1 = tömb2[i].ToString();
- int szum2 = 0;
- for (int jobb = 0; jobb < szo1.Length; jobb++)
- {
- int a = int.Parse(szo1[jobb].ToString());
- szum2 += a;
- }
- if (szum2 % 5 == 0)
- {
- Console.WriteLine(tömb2[i]);
- }
- }
- }
- Console.WriteLine("100-300, van benne 3as");
- for (int i = 0; i < tömb2.Length; i++)
- {
- if (100 < tömb2[i] && 300 > tömb2[i])
- {
- string szo2 = tömb2[i].ToString();
- for (int jobb = 0; jobb < szo2.Length; jobb++)
- {
- int szam2 = int.Parse(szo2[jobb].ToString());
- if (szam2 == 3)
- {
- Console.WriteLine(tömb2[i]);
- break;
- }
- }
- }
- }
- Console.WriteLine("Legnagyobb 7-tel osztható de 3-mal nem osztható szám");
- int max = int.MinValue;
- for (int i = 0; i < tömb2.Length; i++)
- {
- if (tömb2[i] % 3 != 0 && tömb2[i] % 7 == 0)
- {
- if (tömb2[i] > max)
- {
- max = tömb2[i];
- }
- }
- }
- if (max == int.MinValue)
- {
- Console.WriteLine("Nincs ilyen szám!");
- }
- else
- {
- Console.WriteLine(max);
- }
- Console.WriteLine("Szám amiben van 3-as");
- int min = int.MaxValue;
- for (int i = 0; i < tömb2.Length; i++)
- {
- string szo3 = tömb2[i].ToString();
- for (int jobb = 0; jobb < szo3.Length; jobb++)
- {
- int szam3 = int.Parse(szo3[jobb].ToString());
- if (szam3 == 3)
- {
- if (tömb2[i] < min)
- {
- min = tömb2[i];
- }
- }
- }
- }
- if (min == int.MaxValue)
- {
- Console.WriteLine("Nincs ilyen szám!");
- }
- else
- {
- Console.WriteLine(min);
- }
- Console.ReadKey();
- }
- static void feladat6()
- {
- Console.WriteLine("Totó tippsor: ");
- int egy = 0;
- int ketto = 0;
- int xek = 0;
- string[] toto = new string[14];
- int seged = 0;
- while (seged < 14)
- {
- int szam2 = rand.Next(1, 4);
- if (szam2 == 1 && egy < 7)
- {
- toto[seged] = "1";
- ketto++;
- seged++;
- }
- if (szam2 == 2 && ketto < 3)
- {
- toto[seged] = "2";
- ketto++;
- seged++;
- }
- if (szam2 == 3 && xek < 4)
- {
- toto[seged] = "x";
- xek++;
- seged++;
- }
- }
- foreach (string x in toto)
- {
- Console.Write(x + ", ");
- }
- Console.ReadLine();
- }
- static void feladat7()
- {
- int hossz = 5;
- double[] X = new double[hossz];
- for (int i = 0; i < X.Length; i++)
- {
- X[i] = i + 1;
- }
- for (int i = 0; i < X.Length; i++)
- {
- Console.Write(X[i] + ", ");
- }
- Console.WriteLine("\n");
- for (int i = 0; i < X.Length; i++)
- {
- if (i == 0 || i == X.Length - 1)
- {
- if (i == 0)
- {
- X[i] = (X[i] * i + X[i + 1] * (i + 1)) / 2;
- }
- else
- {
- X[i] = (X[i - 1] * (i - 1) + X[i] * i) / 2;
- }
- }
- else
- {
- X[i] = (X[i - 1] * (i - 1) + X[i] * i + X[i + 1] * (i + 1)) / 3;
- }
- }
- for (int i = 0; i < X.Length; i++)
- {
- Console.Write((Math.Floor(X[i] * 100)) / 100 + " ; ");
- }
- }
- static void feladat9()
- {
- int sorszél = 35;
- int sorhossz = 20;
- int[,] bal = new int[sorszél, sorhossz];
- int[,] jobb = new int[sorszél, sorhossz];
- for (int s = 0; s < sorhossz; s++)
- {
- for (int o = 0; o < sorszél; o++)
- {
- bal[o, s] = rand.Next(0, 2);
- jobb[o, s] = rand.Next(0, 2);
- }
- }
- Console.WriteLine("Színházi ülőhelyek:");
- for (int s = 0; s < sorhossz; s++)
- {
- for (int o = 0; o < sorszél; o++)
- {
- if (bal[o, s] == 0)
- {
- Console.Write(bal[o, s]);
- }
- else
- {
- Console.Write(bal[o, s]);
- }
- }
- Console.Write("\n");
- }
- for (int s = 0; s < sorhossz; s++)
- {
- Console.SetCursorPosition(sorszél + 2, s + 2);
- for (int o = 0; o < sorszél; o++)
- {
- if (jobb[o, s] == 0)
- {
- Console.Write(jobb[o, s]);
- }
- else
- {
- Console.Write(jobb[o, s]);
- }
- }
- }
- Console.SetCursorPosition(0, sorhossz + 2);
- Console.WriteLine("Bal oldal");
- Console.SetCursorPosition(sorszél + 2, sorhossz + 2);
- Console.WriteLine("Jobb oldal");
- Console.ReadKey();
- for (int s = 0; s < sorhossz; s++)
- {
- for (int o = 0; o < sorszél - 1; o++)
- {
- if (bal[o, s] == 0 && bal[o + 1, s] == 0)
- {
- Console.SetCursorPosition(o, s + 2);
- Console.Write("00");
- Console.ReadKey();
- }
- }
- }
- for (int s = 0; s < sorhossz; s++)
- {
- for (int o = 0; o < sorszél - 1; o++)
- {
- if (jobb[o, s] == 0 && jobb[o + 1, s] == 0)
- {
- Console.SetCursorPosition(sorszél + 2 + o, s + 2);
- Console.Write("00");
- Console.ReadKey();
- }
- }
- }
- }
- static void feladat10()
- {
- int hossz = 5;
- int min = 1;
- int max = 10;
- int[] tomb1 = new int[hossz];
- for (int i = 0; i < tomb1.Length; i++)
- {
- tomb1[i] = rand.Next(min, max);
- }
- int[] tomb2 = new int[hossz];
- for (int i = 0; i < tomb2.Length; i++)
- {
- tomb2[i] = rand.Next(min, max);
- }
- Console.WriteLine("Tömb 1 elemei:");
- for (int i = 0; i < tomb1.Length; i++)
- {
- Console.Write(tomb1[i] + ", ");
- }
- Console.WriteLine("\n\nTömb 2 elemei:");
- for (int i = 0; i < tomb2.Length; i++)
- {
- Console.Write(tomb2[i] + ", ");
- }
- List<int> kozos_elemek = new List<int>();
- for (int t1 = 0; t1 < tomb1.Length; t1++)
- {
- bool t1_hasznalt = false;
- for (int k = 0; k < kozos_elemek.Count; k++)
- {
- if (tomb1[t1] == kozos_elemek[k])
- {
- t1_hasznalt = true;
- break;
- }
- }
- if (t1_hasznalt == false)
- {
- for (int t2 = 0; t2 < tomb2.Length; t2++)
- {
- if (tomb1[t1] == tomb2[t2])
- {
- kozos_elemek.Add(tomb1[t1]);
- break;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment