can u put solutionsSolution C code include include include u
can u put solutions?
Solution
// C++ code
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main ()
{
int array1[] = {1,4,9,16,9,7,4,9,11};
int size = sizeof(array1)/sizeof(array1[0]);
int array2[size];
for (int i = 0; i < size; ++i)
{
// random numbers in the range of 1 – 25 inclusive.aa
array2[i] = rand() % 25 + 1;
}
int total1 = 0;
int total2 = 0;
for (int i = 0; i < size; ++i)
{
if(array1[i]%2 == 0)
total1 = total1 - array1[i];
else
total1 = total1 + array1[i];
if(array2[i]%2 == 0)
total2 = total2 - array2[i];
else
total2 = total2 + array2[i];
}
cout << \"\ [ \";
for (int i = 0; i < size-1; ++i)
{
cout << array1[i] << \", \";
}
cout << array1[size-1] << \" ] the total is \" << total1 << endl;
cout << \"\ [ \";
for (int i = 0; i < size-1; ++i)
{
cout << array2[i] << \", \";
}
cout << array2[size-1] << \" ] the total is \" << total2 << endl;
return 0;
}
/*
output:
can u put solutions?[ 1, 4, 9, 16, 9, 7, 4, 9, 11 ] the total is 22
[ 9, 12, 3, 16, 19, 11, 12, 18, 25 ] the total is 9
*/
