counting and summing the elements

Write a program in C/C++ that counts and summing the elements (numbers) from the given interval in the array.

please help me to write code for this question
Last edited on
Show what you have so far.

It sounds like a homework question. We can help, but won't do your homework for you.
#include <iostream>

using namespace std;

int main()
{
int array[] = {3,4,7,8,9,10,21,3};
int count = 0; int sum = 0;
for(int i=2;i<5;i++)
{
cout = count+1;
sum = sum+array[i];
}
cout<<cout;
cout<<sum;

return 0;
}

Looks fine, apart from the typo on the first line inside the for loop.

You've made the same typo on the first cout statement.

I'd advise that you tidy it up a little (make sure the indentation is correct, maybe use variables for the interval range), but it should work fine provided the above typos are fixed.

Topic archived. No new replies allowed.