How to find Prime number within Range from 1 to nth in c#
In this Program, you can see how to find Prime number in c# using for loop
using System; using System.Collections.Generic; using System.Text; namespace testconsole { class Program { static void Main(string[] args) { bool isprimenumber = true; Console.WriteLine("Enter nth number"); int totalnumber = Convert.ToInt32(Console.ReadLine()); for (int i = 2; i <= totalnumber; i++) { for (int j = 2; j < totalnumber; j++) { if (i != j && i % j == 0) { isprimenumber = false; break; } } if (isprimenumber) { Console.WriteLine(+i); } isprimenumber = true; } Console.ReadLine(); } } }
Comments
Post a Comment