TopH Little Subarray Sum Solution
Solve in C++:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,a,b,ar[1001],s=0;
while(cin>>n>>a>>b)
{
for(i=0; i<n; i++)
{
cin>>ar[i];
}
for(i=a;i<=b;i++)
{
s=s+ar[i];
}
cout<<s<<endl;
s=0;
}
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,a,b,ar[1001],s=0;
while(cin>>n>>a>>b)
{
for(i=0; i<n; i++)
{
cin>>ar[i];
}
for(i=a;i<=b;i++)
{
s=s+ar[i];
}
cout<<s<<endl;
s=0;
}
}
No comments