#include <stdio.h>
void sliding_window_sum(int arr[], int n, int k) {
// Your logic here
int i=0,j=0,sum=0; // intialize the variable with zero
for(i=0;i<=n-k;i++){ // iterate the loop n-k times
for(j=0;j<k;j++){ // iterate the loop k times
sum = sum + arr[i+j]; // sum + arr[i+j]
}
printf("%d ",sum); // print the sum
sum = 0; // make sum zero
}
}
int main() {
int n, k, arr[100];
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
sliding_window_sum(arr, n, k);
return 0;
}
void sliding_window_sum(int arr[], int n, int k) {
// Your logic here
int i=0,j=0,sum=0; // intialize the variable with zero
for(i=0;i<=n-k;i++){ // iterate the loop n-k times
for(j=0;j<k;j++){ // iterate the loop k times
sum = sum + arr[i+j]; // sum + arr[i+j]
}
printf("%d ",sum); // print the sum
sum = 0; // make sum zero
}
}
Input
5 3 1 2 3 4 5
Expected Output
6 9 12