Written by @Tuncay_Pashayev.
In this problem we have to find number and sum of real numbers that, positive and it's index is divisible by .
For this problem we'll use array. In array indexing is starting from , so we have to create an array with more extra element, like a[n+1]. After creating, we'll check that if the number's index is divisible by and the number is positive. If it is, we'll add this to sum and increase the value of number by . After all of these, we'll print the number and the sum with decimal points.
double a[n + 1], number = 0, sum = 0;Creating an array called and setting it's number of elements to n+1, because indexing is starting from and in problem it wants from us to start it from . Setting the value of to . Also setting the value of to too.
for (int i = 1; i <= n; i++)Checking all the elements of our array.
cin >> a[i];Input the element of array.
if (i % 3 == 0 && a[i] > 0)
{
number++;
sum += a[i];
}If the index of , which one is , is divisible by and is positive, that means we can increase the value of by and also add to current value of .
cout << number << ' ';Printing the .
cout.precision(2);
cout << fixed << sum;Printing the sum with decimal points.