create a number function called sum. function sum will accetp a single integer. asume we call this int parameter position, then the value position will be used to calculate the sum of elements in myIntArray size 1000, whose indices are multiples of position, that is their user passes the argument 5 to the int parameter position . you will need to fine the sum of myIntArray[0] +myIntArray[5] and so forth
#include<iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int myIntArray[1000]={0};
int sum(int x) {
int g=0;
for (int i=0; i<1000; i++) {
if (i%x==0) g+=myIntArray[i];
}
return g;
}
int main() {
srand(time(NULL)); //generate random seed
for (int i=0; i<10; i++) {
myIntArray[i]=rand() % 1000;
cout << myIntArray[i] <<
" ";
}
cout << endl;
int x;
cout << "Enter an integer: ";
cin >> x;
int c=sum(x);
cout << c;
return 0;
}