home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tybc4
/
array2.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-30
|
749b
|
30 lines
/*
C++ program that demonstrates the use of single-dimensional
arrays. The average value of the array is calculated.
The array has its values preassigned internally.
*/
#include <iostream.h>
const int MAX = 10;
main()
{
double x[MAX] = { 12.2, 45.4, 67.2, 12.2, 34.6, 87.4,
83.6, 12.3, 14.8, 55.5 };
double sum = MAX, sumx = 0.0, mean;
int n = MAX;
// calculate sum of observations
cout << "Array is:\n";
for (int i = 0; i < n; i++) {
sumx += x[i];
cout << "x[" << i << "] = " << x[i] << "\n";
}
mean = sumx / sum; // calculate the mean value
cout << "\nMean = " << mean << "\n\n";
return 0;
}