Update array/array_pari.cpp
This commit is contained in:
parent
4f527a39d9
commit
981de52b3a
|
@ -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 <iostream>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#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 <iostream>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#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;
|
||||
}
|
Loading…
Reference in New Issue