Write a program in C# for checking a given number is PRIME or not.
Answer / Jitendra Kumar Paswan
Here's a simple C# program to check if a number is prime:
using System;
namespace PrimeNumberChecker
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a number: ");
int num = Convert.ToInt32(Console.ReadLine());
if (IsPrime(num))
Console.WriteLine(num + " is prime");
else
Console.WriteLine(num + " is not prime");
}
static bool IsPrime(int num)
{
if (num <= 1) return false;
for (int i = 2; i < Math.Sqrt(num); i++)
if (num % i == 0) return false;
return true;
}
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Why is c# a good programming language?
What is the default value of date?
What is difference between ienumerable and iqueryable in c#?
What is architecture of your poroject? how i c an say?
2 Answers Eminosoft, HCL, Phoenix Technologies,
How to find type of variable?
What is difference between overloading and short circuiting?
What are the benefits of using generics?
Does main have to be static c#?
What is ildasm.exe used for?
How many bytes is a char c#?
What is xslt in c#?
What is the components of window?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)