Thanks a lot... Im new to C++, and all this hasnt been taught to us yet in college, just tried doing this with my existing programming knowledge, many syntax's worked though wasnt aware of this rule in C++
Code:
#include<iostream>
using namespace std;
int main()
{
int n=10,m;
cin >> n >> m;
int* stor = new int[n];
int* sums = new int[m];
for(int i=0; i<n; i++)
{
int x;
cin >> x;
stor[i] = x;
}
for(int k=0; k<m; k++)
{
int s,e;
cin >> s>> e;
int sum=0;
for(int j=(s-1); j<e; j++)
{
sum+=stor[j];
}
sums[m] = sum;
}
for(int l=0; l<m; l++)
{
cout << sums[l];
}
return(0);
}
Can someone please correct this code and tell me why am I not getting a output, after some checks I realised that the array sums[] does contain the perfect values that it should, but when trying to print it in the last loop, it is giving garbage values