#include
#include
int main()
{
int n=10, k;
int a[n];
int max = 20, min = -20;
int sum=0;
printf("k (<=10) = ");</span> scanf("%d",&k);
srand (time(NULL));
for (int i=0; i a[i] = (float) rand() / RAND_MAX*(max-min)+min;
printf ("%d ", a[i]);
}
printf("\n");
for (int i = 0; i printf("sum (1..%d) = %d\n", k,sum);
for (int i=1; i<=n-k; i++) {<br> sum = sum-a[i-1]+a[i+k-1];
printf("sum (%d..%d) = %d\n", i+1, i+k, sum);
}
return 0;
}
Пример:
k (<=10) = 5</span>-10 1 -11 -10 16 6 -1 -15 -19 9
sum (1..5) = -14
sum (2..6) = 2
sum (3..7) = 0
sum (4..8) = -4
sum (5..9) = -13
sum (6..10) = -20