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
Differentiate between copy and default constructor.
What is dictionary and hashtable in c#?
What is delegate in c# interview questions?
Which are the loop types available in c#?
What is equal c#?
Why do we use delegates in c#?
What is the difference between dynamic and var in c#?
How do I use the 'using' keyword with multiple objects?
What is _layout cshtml?
What is the syntax for calling an overloaded constructor within a constructor (this() and constructorname() does not compile)?
what optimizations does the c# compiler perform when you use the /optimize+ compiler option?
What is the signature of a method?
What is a console application in c#?
Can you store different types in an array in c#?
What is protected internal modifier in C#?