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
State what is encapsulation and friend function?
What is the types of inheritance?
What are properties in oop?
class type to basic type conversion
Why is polymorphism used?
What is the example of polymorphism?
What is protected in oop?
What are oops methods?
class CTest { public: void someMethod() { int nCount = 0; cout << "This is some method --> " << nCount; } }; int main() { CTest *pctest; pctest->someMethod(); return 0; } It will executes the someMethod() and displays the value too. how is it possible with our creating memory for the class . i think iam not creating object for the class. Thanks in Advance... Prakash
hi all..i want to know oops concepts clearly can any1 explain??
What is class and object with example?
Why is it so that we can have virtual constructors but we cannot have virtual destructors?
write a program to find 2 power of a 5digit number with out using big int and exponent ?
How do you answer polymorphism?
What is the difference between a constructor and a destructor?