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 / randheer
class Program
{
static void Main(string[] args)
{
int a;
int count = 0;
Console.WriteLine("please enter a number");
a = int.Parse(Console.ReadLine());
for (int i = 2; i <= a; i++)
{
int c = a%i;
if (c == 0)
count++;
}
if (count == 1)
{
Console.WriteLine(a + " :is aprime number");
}
else
{
Console.WriteLine(a+" :is not a prime number");
}
Console.ReadKey();
}
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
write a program to find the biggest palindrome in the given string
Illustrate the differences between the system.array.copyto() and system.array.clone()?
How many parameters can a method have c#?
Differentiate between static class and singleton instance?
Name the method of servicebase class?
What is dll hell, and how does .net solve it?
What is a protected class c#?
What is the difference between list and arraylist c#?
What is delegates in c#?
What is icomparable in c#?
What is the main method?
Explain 'structure padding'?
What are expressions c#?
In languages without exception-handling facilities, we could send an error-handling procedure as a parameter to each procedure that can detect errors that must be handled. What disadvantages are there to this method?
What is a class c#?