This question is in C programming.Write a loop that sets newScores to oldScores shifted once left, with element 0 copied to the end. Ex: If oldScores = {10, 20, 30, 40}, then newScores = {20, 30, 40, 10}.Here is the code#include int main(void) {const int SCORES_SIZE = 4;int lowerScores[SCORES_SIZE];int i;for (i = 0; i < SCORES_SIZE; ++i) {scanf("%d", &(lowerScores[i]));}/* Your solution goes here */for (i = 0; i < SCORES_SIZE; ++i) {printf("%d ", lowerScores[i]);}printf("\n");return 0;}

Respuesta :

Answer:

Replace

/* Your solution goes here */

with the following;

for (i = 0; i < SCORES_SIZE - 1; i++) {

newScores[i] = oldScores[i + 1];

}

newScores[SCORES_SIZE - 1] = oldScores[0];

The full program becomes

#include

int main(void) {

const int SCORES_SIZE = 4;

int lowerScores[SCORES_SIZE];

int i;

for (i = 0; i < SCORES_SIZE; ++i) {

scanf("%d", &(lowerScores[i]));

}

for (i = 0; i < SCORES_SIZE - 1; i++) {

newScores[i] = oldScores[i + 1];

}

newScores[SCORES_SIZE - 1] = oldScores[0];

for (i = 0; i < SCORES_SIZE; ++i) {

printf("%d ", lowerScores[i]);

}

printf("\n");return 0;

}

What the included code segment does it that;

for (i = 0; i < SCORES_SIZE - 1; i++) {

newScores[i] = oldScores[i + 1];

}

The above assigns the values of array oldScores to newScores starting with the second element of array oldScores till the last.

newScores[SCORES_SIZE - 1] = oldScores[0];

The above line then assigns the first element of oldScores to the first element of newScores array