How can i write a code in c# to take a number from the user
and then find all the prime numbers till the number entered
by the user.

Answer Posted / shuklaamit565

using System;
class Test2
{
public static void Main()
{
int prime,num=100;

for(int i = 3; i <num; i++)
{
prime = 1;
for(int n = 2; n <= i - 1;
n++)
{
if(i % n == 0)
{
prime = 2;
}
}
if(prime==1)
{
Console.WriteLine( "
is prime :"+i);
}
}
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Get me an image implementation program.

1759


class type to basic type conversion

2116


What is a function in oop?

849


What is methods in oop?

763


What does and I oop mean in text?

880


What does it mean when someone says I oop?

840


What is the main feature of oop?

920


What is the diamond problem in inheritance?

846


Can an interface inherit a class?

806


What is the difference between a constructor and a destructor?

883


What does and I oop mean?

863


What is static modifier?

870


What is encapsulation example?

798


Describe these concepts: Polymorphism, Inheritance and Abstraction.

904


what type of question are asked in thoughtworks pair programming round ?

1986