using System; using System.Windows.Forms; namespace WinFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private Random random = new Random(); private void button1_Click(object sender, EventArgs e) { listBox1.Items.Clear(); // Clear previous results int randomSayi = random.Next(1, 500); asalbul(randomSayi); } private void asalbul(int sayi) { for (int i = 2; i <= sayi; i++) { if (IsPrime(i)) { listBox1.Items.Add(i); // Add prime numbers to the list } } } // Helper method to check if a number is prime private bool IsPrime(int number) { if (number <= 1) return false; if (number == 2) return true; for (int i = 2; i <= Math.Sqrt(number); i++) { if (number % i == 0) { return false; } } return true; } } }