Hi Great Developers,
I have written a program to find prime numbers upto the value entered by user but it is giving odd numbers too. please help me to make this program.
Please help!!! Thanks in advance.
Regards
Sarabjot Singh
I have written a program to find prime numbers upto the value entered by user but it is giving odd numbers too. please help me to make this program.
using System; using System.Collections.Generic; using System.Text; namespace prime_numbers { class Program { static void Main(string[] args) { int num; Console.WriteLine("enter the number upto which you want prime numbers"); num = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("1"); for (int i = 2; i <= num; i++) { if (i % 2 != 0) { for (int j = 2; j <i; j++) { if (i % j == 0) { continue; } else { Console.WriteLine(i); break; } } } } Console.ReadLine(); } } }
Please help!!! Thanks in advance.
Regards
Sarabjot Singh
Last edited by a moderator: