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;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- //értékek beállítása
- Console.WriteLine("Maximum beírható érték: 2.147.483.647");
- Console.Write("Alsó határ: ");
- int min = Convert.ToInt32(Console.ReadLine());
- if(min<2)
- {
- Console.BackgroundColor = ConsoleColor.DarkRed;
- Console.ForegroundColor = ConsoleColor.White;
- Console.Clear();
- Console.WriteLine("!!!HIBA!!! A min értéke nem lehet kisebb 2-nél! Bezáráshoz nyomj bármilyen billentyűt!");
- Console.ReadKey();
- Environment.Exit(0);
- }
- Console.Write("Felső határ: ");
- int max = Convert.ToInt32(Console.ReadLine());
- if(max<=min)
- {
- Console.BackgroundColor = ConsoleColor.DarkRed;
- Console.ForegroundColor = ConsoleColor.White;
- Console.Clear();
- Console.WriteLine("!!!HIBA!!! A max értéke nem lehet kisebb vagy egyenlő a min-nel! Bezáráshoz nyomj bármilyen billentyűt!");
- Console.ReadKey();
- Environment.Exit(0);
- }
- //prímszám vadászat
- for (int n=min;n<=max;n++)
- {
- int c = 0;
- for(int i=2;i<n;i++)
- {
- if(n%i==0)
- {
- c++;
- }
- }
- if(c==0)
- {
- Console.WriteLine(n);
- }
- }
- //vége
- Console.BackgroundColor = ConsoleColor.DarkGreen;
- Console.Write("A folyamat véget ért. Kilépéshez nyomd meg bármelyik billentyűt!");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement