answersLogoWhite

0


Best Answer

#include <iostream>

bool isPrime(int p)

{ if( p<=1 ( p>2 && p%2==0 ))return( false );int max = (int)sqrt(( double ) p ) + 1;for( int i=3; i<=max; i+=2 )if( p%i==0 )return( false );return( true );

}

int main()

{ int primes[10];

int count=0, num=0;

while( count!= 10 )

{num+=num>2?2:1;if( isPrime(num) )primes[count++]=num;}for( int i=0; i<10; ++i )std::cout << primes[i] << std::endl;return( 0 );

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C plus plus program to store first 10 prime numbers in an array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Consider prime numbers between 1 and 10000. Draw a flowchart to display the prime numbers.Write a pseudo code associated with the flowchart in a)?

A) Here's an example of a flowchart and pseudocode that could be used to display the prime numbers between 1 and 10000: Flowchart:
START Set up an array of numbers from 1 to 10000 Set an empty array to store the prime numbers Set i = 2, the first prime number For each number in the array, check if it is divisible by i If it is divisible by i, it is not a prime number and move to the next number in the array If it is not divisible by i, it is a prime number and add it to the prime numbers array Increase i by 1 and go back to step 4 Repeat steps 4 through 7 until i is greater than the square root of 10000 Display the prime numbers array END


What is the term used to describe numbers that can only make 1 array?

They are prime numbers.


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


How are all the area model of the prime numbers similar?

They only have one array.


What do you call numbers that can't be arranged into two rows of a array?

We call them prime nunberds


Why do prime numbers only have one array?

Because they only have one factor pair.


Write a program to print first 100 alternative prime numbers?

This would require some computer knowledge. It can make it easier to find out the prime numbers without figuring it out in your head.


How do you write a VBnet program to find the prime numbers between 100 to 200?

VBnet program to find the prime numbers between 100 to 200?


What is a prime number tree?

a type of array for prime and composite numbers. it is a tree which is divided into smaller and smaller prime numbers. usually at the end of the prime tree there is 2 or more (preferably less than 10) numbers. those numbers usually include 2,3,5,or7


Program for print prime all number from 1 to 100 in foxpro?

Prime numbers are numbers that are only divisible by themselves and the number 1. You can write a program to print all prime numbers from 1 to 100 in FoxPro.


What are the first three prime numbers?

The first three prime numbers are 2,3 and 5.


What is the sum of the first 15 prime numbers?

the sum of the first 15 prime numbers is 328 .