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
Can private class be inherited?
How do you use inheritance in unity?
What is new keyword in oops?
What is meant by multiple inheritance?
Why is it so that we can have virtual constructors but we cannot have virtual destructors?
What are functions in oop?
What is overriding in oops?
why reinterpret cast is considered dangerous?
which feature are not hold visual basic of oop?
Get me a number puzzle game-program
What is data binding in oops?
What is abstraction in oops with example?
What type of loop is a for loop?
What does sksksk mean in text slang?
What is Difference Between Inheritance and creating object and getting data? means Class A extends B{ B.getMethod();} (OR) Class A{ b obj=new B(); obj.getMethod(); }