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 oraimunka
- {
- class Program
- {
- static bool isprime(int szam)
- {
- if (szam == 0 || szam == 1)
- {
- return false;
- }
- else if (szam == 2)
- {
- return true;
- }
- else
- {
- bool prim = true;
- for (int i = 2; i < szam; i++)
- {
- if (szam % i == 0)
- {
- prim = false;
- break;
- }
- }
- return prim;
- }
- }
- static void tombfeltoltes(int[] tomb, int elsoelem, int utolsoelem, int elemszam, bool prime, Random vel)
- {
- bool talal;
- if (elsoelem > utolsoelem)
- {
- int cs;
- cs = elsoelem;
- elsoelem = utolsoelem;
- utolsoelem = cs;
- }
- if (elemszam < 2)
- {
- elemszam = utolsoelem - elsoelem + 1;
- }
- if (prime == true)
- {
- do
- {
- tomb[0] = vel.Next(elsoelem, utolsoelem + 1);
- }while(!isprime(tomb[0]));
- }
- else
- {
- tomb[0] = vel.Next(elsoelem, utolsoelem + 1);
- }
- for (int i = 1; i < elemszam; i++)
- {
- do
- {
- talal = false;
- if (prime == true)
- {
- do
- {
- tomb[i] = vel.Next(elsoelem, utolsoelem + 1);
- }while(!isprime(tomb[i]));
- }
- else
- {
- tomb[i] = vel.Next(elsoelem, utolsoelem + 1);
- }
- for (int j = 0; j < i; j++)
- {
- if (tomb[j] == tomb[i])
- {
- talal = true;
- }
- }
- } while (talal);
- }
- }
- static void Main(string[] args)
- {
- int elemszam = 5;
- int[] tomb = new int[elemszam];
- int[] tipp = new int[5] {8, 14, 17, 32, 81};
- Random vel = new Random();
- int talalat = 0;
- for (int j = 0; j < 10; j++)
- {
- tombfeltoltes(tomb, 1, 90, elemszam, false, vel);
- for (int i = 0; i < elemszam; i++)
- {
- Console.Write("{0}\t", tomb[i]);
- }
- talalat = 0;
- for (int i = 0; i < elemszam; i++)
- {
- for (int k = 0; k < 5; k++)
- {
- if (tomb[i] == tipp[k])
- {
- talalat++;
- }
- }
- }
- Console.WriteLine(talalat);
- Console.WriteLine();
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement