Untitled
unknown
plain_text
3 years ago
1.4 kB
3
Indexable
#include <iostream> #include <random> using namespace std; int GetInteger(char *message); int GetRow(); void FillIn(int data[], int low, int high); void Display(int data[][5]); int CountLess(int data[], int bound); int main(){ int data[5][5]; int seed, row, bound; seed = GetInteger("Enter seed: "); srand(seed); FillIn(data[0], 10, 20); Display(data); row = GetRow(); bound = GetInteger("Enter bound: "); cout << "There are " << CountLess(data[row], bound) << " number in row " << row << " less than " << bound << endl; return 0; } int GetInteger(char *message){ int number; cout << message; cin >> number; return number; } int GetRow(){ int input; do{ cout << "Select a row: "; cin >> input; if(input < 0 || input >= 5) cout << "Invalid row" << endl; }while(input < 0 || input >= 5); return input; } void FillIn(int data[], int low, int high){ for(int i = 0 ; i < 25 ; i++) data[i] = (rand() % (high - low)) + low; return; } void Display(int data[][5]){ for(int i = 0 ; i < 5 ; i++){ cout << i << ": "; for(int j = 0 ; j < 5 ; j++){ cout << data[i][j] << " "; } cout << endl; } } int CountLess(int data[], int bound){ int count = 0; for(int i = 0 ; i < 25 ; i++){ if(data[i] < bound) count++; } }
Editor is loading...