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> using namespace std; bool isPrime(int number) { int divisor; for(divisor = 2; divisor <= number / 2; divisor++) { if(number % divisor == 0) { return false; } } return true; } int main() { int number; for(number = 2; number <= 20; number++) { if(isPrime(number)) { cout << number << " is a prime number\n"; } else { cout << number << " is not a prime number\n"; } } return 0; }

Questions about programming?Chat with your personal AI assistant