odd_array.cpp
#include <iostream>
using namespace std;
double average(int a[], int size);
int main( )
{
int i, size, sum = 0;
double ave;
cout << "Enter the size:\t";
cin >> size;
cout << endl;
int odd[size];
for (i = 0; i < size; i++)
odd[i] = 2*i + 1;
ave = average(odd, size);
for (i = 0; i < size; i++)
sum = sum + odd[i];
for (i = 0; i < size; i++)
cout << "Index "
<< i << " odd value " << odd[i] << endl;
cout << "The sum is: "
<< sum << endl;
cout << "The average
is: " << ave << endl;
return 0;
}
double average(int a[], int size)
{
int sum = 0;
for (int i = 0; i < size;
i++)
sum = sum + a[i];
return(static_cast<double>(sum/size));
}