Little Subarray Sum
Limits
1s, 512 MB
Given
an array of N numbers and two indices, determine the sum of the numbers
in the array between (and including) those two indices.
Take this array for example:
Take this array for example:
13 7 20 1 8
The sum of the numbers between and including the indices 1 and 4 is:7 + 20 + 1 + 8 = 36
Input
The first line of the input will contain three integers N, A, B (0 < N < 100, 0 ≤ A < B < N). A and B are the two indices.
The following line will contain N integers, each between 1 and 1000.
The following line will contain N integers, each between 1 and 1000.
Output
Print the sum of the subarray.
#include<stdio.h>
int main()
{
int n,a,b,i,sum=0;
scanf("%d %d %d", &n, &a, &b);
int arr[n];
for(i=0;i<n;i++)
scanf("%d", &arr[i]);
for(i=a;i<=b;i++)
{
sum+=arr[i];
}
printf("%d",sum);
}