Prime Number Program in C#
C# Programming Language Loop control in C# Language (Article) Loop control in C# Language (Program)
415
If you don't know what is prime number please read form this tutorial. Prime Number & Prime Factors
Program:
using System; public class PrimeNumberExample { public static void Main(string[] args) { int n, i, m=0, flag=0; Console.Write("Enter the Number to check Prime: "); n = int.Parse(Console.ReadLine()); m=n/2; for(i = 2; i <= m; i++) { if(n % i == 0) { Console.Write("Number is not Prime."); flag=1; break; } } if (flag==0) Console.Write("Number is Prime."); } }
Output:
output 1: Enter the Number to check Prime: 17 Number is Prime. Output 2: Enter the Number to check Prime: 57 Number is not Prime.
Explanation:
None
This Particular section is dedicated to Programs only. If you want learn more about C# Programming Language. Then you can visit below links to get more depth on this subject.