From 981de52b3a49cd04ed0d254456bf1c73fed5975a Mon Sep 17 00:00:00 2001 From: Vichingo455 Date: Thu, 21 Nov 2024 07:16:38 +0000 Subject: [PATCH] Update array/array_pari.cpp --- array/array_pari.cpp | 82 ++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/array/array_pari.cpp b/array/array_pari.cpp index d6432ea..336c10b 100644 --- a/array/array_pari.cpp +++ b/array/array_pari.cpp @@ -1,42 +1,42 @@ -/* -AUTHOR: Manuel Vichi -The program asks in input 10 values, stores them in an array and then determines if all stored values are peer numbers or not. -*/ -#include -#include -#include -#include -#define ARRAY_SIZE 10 //The size of the integers' array -using namespace std; -//Check if a number is peer -bool isPeer(int number) { - return number % 2 == 0; -} - -//Print if all numbers on an array are peers or not -void printIfPeersOnPeerPositions(int array[]) { - int array_size = sizeof(array) / sizeof(array[0]); - int number_peers = 0; - for (int i = 0; i < array_size; i++) { - if (isPeer(array[i])) { - number_peers++; - } - i++; - } - if (number_peers == array_size) - cout << "All numbers you gave me are peers." << endl; - else - cout << "Not all numbers you gave me are peers." << endl; -} - -//Main function -int main() { - int integers[ARRAY_SIZE]; - for (int i = 0; i < ARRAY_SIZE; i++) { - cout << "Type a number and press enter (Remaining to type: " << ARRAY_SIZE - i - 1 << "). "; - cin >> integers[i]; - cout << endl; - } - printIfPeersOnPeerPositions(integers); - return 0; +/* +AUTHOR: Vichingo455 +The program asks in input 10 values, stores them in an array and then determines if all stored values are peer numbers or not. +*/ +#include +#include +#include +#include +#define ARRAY_SIZE 10 //The size of the integers' array +using namespace std; +//Check if a number is peer +bool isPeer(int number) { + return number % 2 == 0; +} + +//Print if all numbers on an array are peers or not +void printIfPeersOnPeerPositions(int array[]) { + int array_size = sizeof(array) / sizeof(array[0]); + int number_peers = 0; + for (int i = 0; i < array_size; i++) { + if (isPeer(array[i])) { + number_peers++; + } + i++; + } + if (number_peers == array_size) + cout << "All numbers you gave me are peers." << endl; + else + cout << "Not all numbers you gave me are peers." << endl; +} + +//Main function +int main() { + int integers[ARRAY_SIZE]; + for (int i = 0; i < ARRAY_SIZE; i++) { + cout << "Type a number and press enter (Remaining to type: " << ARRAY_SIZE - i - 1 << "). "; + cin >> integers[i]; + cout << endl; + } + printIfPeersOnPeerPositions(integers); + return 0; } \ No newline at end of file