#include <iostream>
using std::cout;
using std::endl;
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
int main()
{
int bc[30];
int sumEven = 0, sumEvenIndex = 0;
srand(time(0));
for(int i = 0; i < 30; i++)
{
bc[i] = rand() % 51;
if(bc[i] % 2 == 0)
{
sumEven += bc[i];
}
if(i % 2 == 0)
{
sumEvenIndex += bc[i];
}
cout << bc[i] << ' ';
}
cout << endl << endl;
int temp, biggest;
for(int i = 0; i < 30 - 1; i++)
{
biggest = i;
for(int j = i + 1; j < 30; j++)
{
if(bc[biggest] < bc[j])
{
biggest = j;
}
}
temp = bc[i];
bc[i] = bc[biggest];
bc[biggest] = temp;
}
for(int i = 0; i < 30; i++)
{
cout << bc[i] << ' ';
}
cout << "\nThe sum of elements with even indices = " << sumEvenIndex
<< "\nThe sum of even elements = " << sumEven << endl;
return 0;
}
#include <iostream>
using std::cout;
using std::endl;
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
int main()
{
int a[12];
for(int i = 0; i < 12; i++)
{
a[i] = rand() % 21;
cout << a[i] << ' ';
}
cout << endl;
int temp;
for(int i = 0, j = 11; i < j; i++, j--)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
for(int i = 0; i < 12; i++)
{
cout << a[i] << ' ';
}
cout << endl;
return 0;
}