Asp . Net || SQL Server
Friday, 23 January 2015
C # program to check a given number is a prime number or not
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PrimeNumbers
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number to check :");
int num, k = 0;
num = int.Parse(Console.ReadLine());
for (int i = 1; i <= num; i++)
{
if (num % i == 0)
{
k++;
}
}
if (k == 2)
{
Console.WriteLine("Entered number is a prime number");
}
else
{
Console.WriteLine("Entered number is not a prime number");
}
Console.ReadLine();
}
}
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment