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

Is react oop?

819


They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?

1621


Is abstract thinking intelligence?

797


Get me a number puzzle game-program

1929


What is difference between multiple inheritance and multilevel inheritance?

880


What is coupling in oops?

824


Why polymorphism is used in oops?

792


What is abstraction with example?

827


What are the three main types of variables?

834


What is an interface in oop?

780


Why can't we have instance(stack) of a class as a member of the same class like eg.Class A{A obj;} as we can have self refential pointer

1901


Why is oop better than procedural?

809


Question: Write a program that prints a paycheck. Ask the program user for the name of the employee, the hourly rate, and the number of hours worked. If the number of hours exceeds 40, the employee is paid “time and a half”, that is, 150 percent of the hourly rate on the hours exceeding 40. Be sure to use stepwi se refine ment and break your solution into several functions. Use the int_name function to print the dollar amount of the check.

954


What do you mean by abstraction?

819


what is the sylabus for priliminaries?

1906