Create a function named test2Problem2that contains a list comprehension. This function will take asingle integer parameter nand returns a list of length n of every other prime. (Please note that primes start at 2.)There will be a 10 point deduction for not using a list comprehension to solve this problem.List comprehensions have this form: [ expression for item in list if conditional ]In:10Out:[2,5,11,17,23,31,41,47,59,67]In:7Out:[2,5,11,17,23,31,41]

Respuesta :

Answer:

C++.

Explanation:

#include <iostream>

using namespace std;

/////////////////////////////////////////////////////////

void printPrime(int n) {

   if (n > 0) {

       cout<<"[2";

       for (int i=3; i<=n; i++) {

           bool isPrime = true;

           

           for (int j=2; j<i; j++) {

               if (i % j == 0) {

                   isPrime = false;

                   break;

               }

           }

           

           if (isPrime == true)

               cout<<", "<<i;

       }

   }

   else {

       cout<<"Invalid input";

   }

   cout<<"]";

}

/////////////////////////////////////////////////////////

int main() {

   int n;

   cout<<"Enter positive integer: ";

   cin>>n;

   printPrime(n);

   return 0;

}

ACCESS MORE
EDU ACCESS