1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <iostream>
#include <fstream>
using namespace std;
const int ROWS = 4;
const int COLS = 4;
float findSumAndAve(int box[][COLS]);
bool findValue(int box[][COLS], int);
int main()
{
int sum=0;
double average=0;
int v;
int box[ROWS][COLS] = { {11,8,0,-4}, {74,5,13,42}, {29,-7,45,4}, {100,23,-3,61} };
findSumAndAve(box);
cout << "The sum of the array is: " << sum << endl;
cout << "The average of the array is: " << average << endl;
cout << "Please enter an integer: ";
cin >> v;
bool found = findValue(box, v);
if (found==true)
cout << "The integer " << v << " has been found in the array" << endl;
else
cout << "Integer not found" << endl;
system("pause");
return 0;
}
float findSumAndAve(int box[][COLS])
{
int sum = 0;
double average = 0;
for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < COLS; j++)
{
sum += box[i][j];
}
}
return sum;
average = sum / (ROWS * COLS);
return average;
}
bool findValue(int box[][COLS], int v)
{
for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < COLS; j++)
{
if (box[i][j] == v)
return true;
}
}
return false;
}
|