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
What is inline function in c#?
Difference between abstract classes and interfaces
What is the base class for array types?
How many destructors can a class have?
What is called method in c#?
What is the difference between a field and a property in c#?
Is python easier than c#?
What is parseexact c#?
What is delegates in c# and uses of delegates?
What are some examples of desktop applications?
Can a method be sealed in c#?
What is bit in c#?
what is the equivalent to regsvr32 and regsvr32 /u a file in .net development?
What is linq c#?
What is reflection c#?