Anderson Pozo

Generation

generate functionThu, 22 Jun 2023

Dada una lista de 10 números enteros. Calcular e informar el primer número par, el primer número primo.

#include <iostream> #include <list> #include <cmath> using namespace std; list<int> l; bool isPrime(int n) { if (n == 2 or n == 3) return true; if (n == 1 or n % 2 == 0) return false; int root = sqrt(n); for (int i = 3; i <= root; ++i) if (n % i == 0) return false; return true; } int main() { l.push_back(2); l.push_back(3); l.push_back(5); l.push_back(7); l.push_back(1); l.push_back(4); l.push_back(6); l.push_back(8); l.push_back(9); l.push_back(10); list<int>::iterator it = l.begin(); int first_

Questions about programming?Chat with your personal AI assistant