Question: %) Write a C# program that computes and prints the prime numbers starting from 2 until 500, with 8 in a row. At the end

%) Write a C# program that computes and prints the prime numbers starting from 2 until 500, with 8 in a row. At the end it also shows how many prime numbers there are from 2 to 500.

For your convenience, the method to check prime number is attached here.

public static bool isPrime(int k)

{ // method to check if k is a prime

for (int j = 2; j <= Math.Sqrt((double)k); j++) // Need to check up to square root only

if (k % j == 0) // if j divides k

return false;

return true;

}

(15%) Enhance the C# program so that you have an integer n input from the keyboard. Find the prime numbers from 2 till n like you do in part (a). Test with n = 256, 304, and 600.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!