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
How Reflection is used and what it's significance ?
What is the data encapsulation?
What is the name of c# compiler?
What does protected internal access modifier mean?
What is definition in c#?
What does || mean in programming?
Is c# good for games?
What is icomparer in c#?
What are the new features in c# 2.0?
What is a c# delegate?
What is reference types in c#?
what is partial assembly reference
How many bytes is an int in c#?
What is managed code?
What is the difference between returning iqueryable vs ienumerable?