Advertisement
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 Gyak1
- {
- class Program //Két dimenziós tömb feltöltése, kiíratása
- {
- static bool isprime(int szam)
- {
- bool prim;
- if (szam == 0 || szam == 1)
- {
- prim = false;
- }
- else if (szam == 2)
- {
- prim = true;
- }
- else
- {
- prim = true;
- bool kilep = false;
- for (int i = 2; i < Math.Sqrt(szam) && !kilep; i++)
- {
- if (szam % i == 0)
- {
- prim = false;
- kilep = true;
- }
- }
- }
- return prim;
- }
- static bool paros(int szam)
- {
- bool par;
- if (szam % 2 == 0)
- {
- par = true;
- }
- else
- {
- par = false;
- }
- return par;
- }
- static void keresparos(int[,] tomb)
- {
- for (int j = 0; j < tomb.GetLength(0); j++)
- {
- for (int i = 0; i < tomb.GetLength(1); i++)
- {
- if (paros(tomb[j, i]) == true)
- {
- Console.Write("{0} ", tomb[j, i]);
- }
- }
- }
- }
- static void primkeres(int[,] tomb)
- {
- for (int j = 0; j < tomb.GetLength(0); j++)
- {
- for (int i = 0; i < tomb.GetLength(1); i++)
- {
- if (isprime(tomb[j, i]) == true)
- {
- Console.Write("{0} ", tomb[j, i]);
- }
- }
- }
- }
- static void tombfeltolt(int[,] t, Random r)
- {
- for (int j = 0; j < t.GetLength(0); j++)
- {
- for (int i = 0; i < t.GetLength(1); i++)
- {
- t[j, i] = r.Next(10, 100);
- }
- }
- }
- static void kiir(int[,] tomb)
- {
- for (int j = 0; j < 5; j++)
- {
- for (int i = 0; i < 5; i++)
- {
- Console.Write("{0} ", tomb[j, i]);
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- int[,] tomb = new int[5, 5];
- Random vel = new Random();
- tombfeltolt(tomb, vel);
- kiir(tomb);
- Console.WriteLine();
- keresparos(tomb);
- Console.WriteLine();
- primkeres(tomb);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement