Anderson Pozo

Generation

generate functionWed, 21 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 <cmath> using namespace std; bool isPrime(int number) { if(number < 2) { return false; } for(int i = 2; i < number; i++) { if (number % i == 0) { return false; } } return true; } int main() { int number[10]; int even = 0; int prime = 0; for (int i = 0; i < 10; i++) { cout << "Enter a number:"; cin >> number[i]; } for (int i = 0; i < 10; i++) { if (number[i] % 2 == 0 && even == 0) { even = number[i]; } } for (int i = 0; i < 10; i++) { if (isPrime(number[i])

Questions about programming?Chat with your personal AI assistant