64.6k views
5 votes
Write a program that displays the first 50 prime numbers in five lines, each of which contains 10 numbers. An integer greater than 1 is prime if its only positive divisor is 1 or itself. For example, 2, 3, 5, and 7 are prime numbers, but 4, 6, 8, and 9 are not.

User Sth
by
7.7k points

1 Answer

3 votes

Final answer:

To display the first 50 prime numbers in five lines, with each line containing 10 numbers, we can use loops and a prime checking function in programming.

Step-by-step explanation:

To display the first 50 prime numbers in five lines, with each line containing 10 numbers, we can use loops and a prime checking function in programming.

Here is an example code in Python:

def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True

prime_count = 0
for num in range(2, 1000):
if is_prime(num):
prime_count += 1
print(num, end=' ')
if prime_count % 10 == 0:
print()
if prime_count == 50:
break

This code defines a function is_prime() to check if a number is prime. Then it uses a loop to iterate over the numbers from 2 to 1000, checks if each number is prime, and prints it if it is. The loop stops when 50 prime numbers have been printed.

User Ebpo
by
7.7k points

No related questions found