2 dimentional arrays that determines the odd number among 12 inputs
#include <iostream>
using namespace std;
int main() {
const int line = 3;
const int col = 4;
int array[line][col] = {};
int i,j;
cout << "Enter twelve numbers:\n";
for( i=0; i<line; ++i) {
for( j=0; j<col; ++j) {
cin >> array[i][j];
if(!cin) {
cout << "Bad input\n";
return 1;
}
}
}
cout<<"Odd: ";
for( i=0; i<line; ++i) {
for( j=0; j<col; ++j) {
if(array[i][j]%2==1)
cout<<array[i][j]<<' ';
}
}
return 0;
}
Comments
Leave a comment