Final answer:
The solution involves writing a for loop to decrement each element in the lowerScores array by 1, unless the element is 0 or negative, in which case it is set to 0. This modifies the array according to the specified behavior.
Step-by-step explanation:
To write a loop that subtracts 1 from each element in the array lowerScores and assigns 0 to elements that are already 0 or negative, you can use the following code snippet inside the main function:
/* Your solution goes here */
for (i = 0; i < SCORES_SIZE; ++i) {
if (lowerScores[i] > 0) {
lowerScores[i] = lowerScores[i] - 1;
} else {
lowerScores[i] = 0;
}
This loop checks each element of the lowerScores array. If the element is greater than zero, it decrements it by 1. Otherwise, it sets the element to 0. By performing this operation, the initial lowerScores = {5, 0, 2, -3} becomes {4, 0, 1, 0} as expected.The loop should iterate through each element in the lowerScores array and subtract 1 from each element. If the element is already 0 or negative, it should be assigned 0. Here's the solution:
for (i = 0; i < SCORES_SIZE; ++i) {
if (lowerScores[i] > 0 lowerScores[i]--; else lowerScores[i] = 0}This loop checks the value of each element in the array and uses an if statement to determine whether to subtract 1 or assign 0. Finally, the array is printed using another loop.