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 nedikprimtomb
- {
- class Program
- {
- static bool isprime(int szam)
- {
- if (szam < 2)
- {
- 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; // Akkor juszt is breaket használok. :)
- }
- }
- return prim;
- }
- }
- static void Main(string[] args)
- {
- int b = 1, tal = 0;
- uint elemszam;
- string a;
- Console.Write("Adja meg hogy az első hány db prímet szeretné kiíratni: ");
- a = Console.ReadLine();
- elemszam = Convert.ToUInt32(a);
- int[] tomb = new int[elemszam];
- do
- {
- if(isprime(b))
- {
- tomb[tal++] = b;
- }
- b++;
- }while (tal < elemszam);
- for (int j = 0; j < elemszam; j++)
- {
- Console.WriteLine("A {0}. elem = {1}", j+1, tomb[j]);
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement