Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Can private class be inherited?

1226


How do you use inheritance in unity?

1127


What is new keyword in oops?

1099


What is meant by multiple inheritance?

1336


Why is it so that we can have virtual constructors but we cannot have virtual destructors?

5054


What are functions in oop?

1120


What is overriding in oops?

1158


why reinterpret cast is considered dangerous?

2450


which feature are not hold visual basic of oop?

2235


Get me a number puzzle game-program

2318


What is data binding in oops?

1150


What is abstraction in oops with example?

1353


What type of loop is a for loop?

1133


What does sksksk mean in text slang?

2180


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(); }

2698