Answer to Question #25086 in C++ for chidi

Question #25086
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
Expert's answer
#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;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


Assignment Expert
19.03.13, 14:13

You're welcome. We are glad to be helpful.
If you really liked our service please press like-button beside answer field. Thank you!

19.03.13, 02:40

I am very exited to see my question solved. i am highly appreciated thanks

Leave a comment

Ask Your question

New on Blog