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 75 76 77 78 79 80 81 82

#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
void createArray(int arr[],int size);
int sum(int arr[],int size);
double average(int arr[],int size);
int smallestAt(int arr[],int size);
int largestAt(int arr[],int size);
int main() {
const int SIZE=10000;
int arr[SIZE];
int total, minIdx,maxIdx;
double avg;
srand(time(0));
createArray(arr,SIZE);
total=sum(arr,SIZE);
avg=average(arr,SIZE);
minIdx=smallestAt(arr,SIZE);
maxIdx=largestAt(arr,SIZE);
cout<<"Total: "<<total<<endl;
cout<<"Average: "<<avg<<endl;
cout<<"Smallest element: "<<arr[minIdx]<<" at "<<minIdx<<endl;
cout<<"Largest element: "<<arr[maxIdx]<<" at "<<maxIdx<<endl;
cin.get();
return 0;
}
void createArray(int arr[],int size)
{
for(int i=0;i<size;i++)
{
arr[i]=rand()%5000 +1;
}
return;
}
int sum(int arr[],int size)
{
int total=0;
for(int i=0;i<size;i++)
{
total+=arr[i];
}
return total;
}
double average(int arr[],int size)
{
int total=sum(arr,size);
return (double)total/(double)size;
}
int smallestAt(int arr[],int size)
{
int small=0;
for(int i=1;i<size;i++)
{
if(arr[small]>arr[i])
small=i;
}
return small;
}
int largestAt(int arr[],int size)
{
int large=0;
for(int i=1;i<size;i++)
{
if(arr[large]<arr[i])
large=i;
}
return large;
}
 