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
|
#include <iostream>
#include "stdlib.h"
using namespace std;
const int INDEX = 10;
void initialize(int);
int sumAvg(int&, int&, int);
int bigSmall(int&, int&, int);
int main()
{
int sum=0, avg=0, big=0, small=0, i, array[INDEX];
initialize(array);
cout << "Please enter 10 integers (separate with spaces):\n";
for(i=0;i<INDEX;i++)
cin >> array[i];
sumAvg(sum, avg, array);
cout << "\nThe sum of the 10 integers you entered is: " << sum << "\n"
<< "The average of the 10 integers you entered is: " << avg << "\n";
bigSmall(big, small, array);
cout << "The largest number you entered is: " << big << endl
<< "The smallest number you entered is: " << small << endl;
return 0;
}
void initialize(int a[])
{
int j;
for(j=0;j<INDEX;j++)
a[j] = 0;
}
int sumAvg(int& sum, int& avg, int b[])
{
sum=0;
int k=0;
for(k=0;k<INDEX;k++)
sum=sum+b[k];
avg = sum/10;
return 0;
}
int bigSmall(int& big, int& small, int c[])
{
int l=0;
for(l=0;l<INDEX;l++)
{
if(c[l]>big)
big=c[l];
}
small=big;
for(l=0;l<INDEX;l++)
{
if(c[l]<small)
small=c[l];
}
return 0;
}
|