Create a Visual Studio console project named exercise071 containing a main() program that in a single statement declares an int array named primes and initializes the 5 entries to the first prime numbers. The primes start at 2 since 1 is not a prime number. Display the array on a single console line beginning with "Primes: " and a blank separating the numbers. A loop is not required.
Code:
#include <iostream>
using namespace std;
int main()
{
int primes[5]={2,3,5,7,11};
/*Here we initialized the array primes with 5 elements 2 3 5 7
11*/
cout<<"Primes:"<<primes[0]<<"
"<<primes[1]<<" "<<primes[2]<<"
"<<primes[3]<<" "<<primes[4];
/*By using cout we print the 5 prime numbers with black spaces
between them*/
return 0;
}
Output:
Indentation:
Get Answers For Free
Most questions answered within 1 hours.