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 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
using namespace std;
void getlist (int [], int &);
void putlist (const int [], int);
float meanAverage (const int [], int);
int minIndex (const int [], int);
void leftRotate (int [], int);
const int MAXSIZE = 50;
int i, length, sum;
float average;
int mylist [MAXSIZE];
int main ( void )
{
getlist (mylist, length);
putlist (mylist, length);
meanAverage (mylist, length);
cout << "The average is " << average << endl;
cout << "The minimum value index is " << minIndex (mylist, length) << endl;
leftRotate (mylist, length);
for( i=0; i < mylist [i]; ++i)
cout << i << " " << mylist[i] << endl;
system ("PAUSE");
return 0;
}
void getlist (int mylist[], int & lenght)
{
cout << "Enter the number of Array Elements, Maximum " << MAXSIZE << endl;
cin >> length;
for (i = 0; i < length; i ++)
{
cout << "Enter the next array element\n";
cin >> mylist [i];
}
}
void putlist (const int mylist [], int lenght)
{
cout << "Array elements\n";
for (i = 0; i < length; i ++)
cout << i << " " << mylist [i] << endl;
}
float meanAverage (const int mylist [], int length)
{
sum = 0;
for (i = 0; i < length; i ++)
sum = sum + mylist [i];
average = float (sum) / float (length) + 0.5;
return average;
}
int minIndex (const int mylist [MAXSIZE], int numels)
{
int i, min = mylist[0];
for (i = 1; i < numels; i++)
if (min > mylist[i])
min = mylist[i];
return min;
}
void leftRotate (int x[], int length) //output error
{
int temp;
temp = x[0];
if (length == 0);
else
{
leftRotate ( &x[1], --length );
}
x[0] = x[length];
x[length] = temp;
}
|