Respuesta :
Answer:
The program to this question can be given as:
Program:
#include<stdio.h> //header file.
int main()
//main function
{
int i; //define variables.
int bonusScores[]={10,20,30,40}; //define array.
printf("Values:"); //message
for (i = 0; i < 4; ++i) //loop for print values.
{
printf("%d ", bonusScores[i]);
}
for (i = 0; i <4; i++) //loop for convert values
{
if (( bonusScores[i] <= bonusScores[i +1] ) || (bonusScores[i] < bonusScores [i+1])) //check array elements
{
bonusScores[i] = (bonusScores [i] + bonusScores[i+1]); //add values
}
else
{ bonusScores[i] = bonusScores[i];
}
}
printf("\nReturn values:"); //message
for (i = 0; i < 4; ++i) //loop for print values
{
printf("%d ", bonusScores[i]); //print values
}
printf("\n");
return 0;
}
Output:
Values:10 20 30 40
Return values:30 50 70 40
Explanation:
In the above c++ programming code firstly we define the header file. Then we define the main function in this function we define variable that name is given in the question that is i. Variable i is used in the loop for a print array. Then we define and initialize an array. The array name is and elements are define in the question that is bonusScores[]={10,20,30,40}. Then we use the loop for print array elements. We use the second time in this loop we check array elements by using the condition statements in if block we add the elements and in else we print last value. At the last, we use the loop for print array.