hi,
I am a begineer to c sharp. I have written a code for
finding out prime numbers. Can anyone identify what are the
flaws in my code.
Kindly donot complex the code or present logic because i am
new to c sharp and just started learning programming
language.Thanks in advance.

class Program
{
static void Main(string[] args)
{
int a,b=1;
a = int.Parse(Console.ReadLine());
c= int.Parse(Console.ReadLine());
if (a % b == 0 && a % 2 != 0 && a % a == 0)

Console.WriteLine(a);
else if (a % b == 0 && a % 2 == 0)
Console.WriteLine(a%2);
Console.WriteLine("Number is not
PRIME");
Console.ReadLine();


}
}
}

Answer Posted / renuka thakur

Hi im Renu , once check out this


class Program
{
static void Main(string[] args)
{
int a,b=1;
Console.WriteLine("enter a number: ");
a = int.Parse(Console.ReadLine());

if (a % b == 0 && a % 2 != 0 && a % a == 0)
{
Console.WriteLine(a + " is a prime number");
}
else
if (a % b == 0 && a % 2 == 0)
{
Console.WriteLine(a % 2);
Console.WriteLine("Number is notPRIME");
}
Console.ReadLine();

}
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How Reflection is used and what it's significance ?

717


What is the data encapsulation?

653


What is the name of c# compiler?

854


What does protected internal access modifier mean?

762


What is definition in c#?

649


What does || mean in programming?

673


Is c# good for games?

659


What is icomparer in c#?

700


What are the new features in c# 2.0?

720


What is a c# delegate?

803


What is reference types in c#?

694


what is partial assembly reference

730


How many bytes is an int in c#?

691


What is managed code?

730


What is the difference between returning iqueryable vs ienumerable?

704