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

What is this pointer in oop?

551


What is oops in programming?

562


Templates mean

1587


What is the purpose of polymorphism?

675


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.

693






is there any choice in opting subjects like 4 out of 7

1727


What is difference between pop and oop?

601


What is constructor in oop?

585


What is the point of oop?

648


What is data binding in oops?

582


What is destructor in oop?

621


Can we have inheritance without polymorphism?

608


Please send ford technologies placement paper 2 my mail id

1652


write a program using c++ to implement single contiguous memory mangement techniques.display the content of the main memory after yhe allocation of jobs and percentage of the wastage of the main memory

2752


what is graphics

2009