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
Why polymorphism is used in oops?
Why is object oriented programming so hard?
What is the fundamental idea of oop?
What is the purpose of enum?
What is class in oop with example?
write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.
What is the point of oop?
What are the 3 principles of oop?
How Do you Code Composition and Aggregation in C++ ?
Why is oop better than procedural?
I have One image (means a group photo ) how to split the faces only from the image?............ please send the answer nagadurgaraju@gmail.com thanks in advace...
Write a program to sort the number with different sorts in one program ??
What is object-oriented programming? Webopedia definition
What is difference between oop and pop?
What does I oop mean?