Question

CHALLENGE ACTIVITY 9.7.1: Decrement array elements. Write a loop that subtracts 1 from each element in lowerScores. If the el

for c

0 0
Add a comment Improve this question Transcribed image text
Answer #1

main.cpp x main.cpp x include Carch X src Car.cpp X main.cpp X main.cpp X main.cpp x main.cpp x main.cpp x main.cpp #include

OD: Learning CPP\Programs CheggProblem\bin\Debug\CheggProblem.exe 5 0 2-3 4 0 10 execution time : 13.340 s Process returned o

Program:

#include <stdio.h>
#include <stdlib.h>

int main()
{

const int SCORES_SIZE = 4;
intlowerScores[SCORES_SIZE];
inti;

for (i = 0; i < SCORES_SIZE; ++i){
scanf("%d", &(lowerScores[i]));
}

/**Solution:
iterate through the lowerScores array and check if the element is Negative or not
if negative subtract 1 from array element else assign zero to it.
*/
for (i = 0; i < SCORES_SIZE; ++i){
if (lowerScores[i] > 0) {
lowerScores[i] = lowerScores[i] - 1;
} else {
lowerScores[i] = 0;
}
}

for (i = 0; i < SCORES_SIZE; ++i){
printf("%d ", lowerScores[i]);
}
printf("\n");
return 0;
}

Add a comment
Know the answer?
Add Answer to:
for c CHALLENGE ACTIVITY 9.7.1: Decrement array elements. Write a loop that subtracts 1 from each...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Write a loop that subtracts 1 from each element in lowerScores. If the element was...

    C++ Write a loop that subtracts 1 from each element in lowerScores. If the element was already 0 or negative, assign 0 to the element. Ex: lowerScores = {5, 0, 2, -3} becomes {4, 0, 1, 0}. #include <iostream> using namespace std; int main() { const int SCORES_SIZE = 4; int lowerScores[SCORES_SIZE]; int i; for (i = 0; i < SCORES_SIZE; ++i) { cin >> lowerScores[i]; } /* Your solution goes here */ for (i = 0; i < SCORES_SIZE;...

  • Write a loop that subtracts 1 from each element in lowerScores. If the element was already...

    Write a loop that subtracts 1 from each element in lowerScores. If the element was already 0 or negative, assign 0 to the element. Ex: lowerScores = {5, 0, 2, -3} becomes {4, 0, 1, 0}. public class StudentScores { public static void main (String [] args) { final int SCORES_SIZE = 4; int[] lowerScores = new int[SCORES_SIZE]; int i = 0; lowerScores[0] = 5; lowerScores[1] = 0; lowerScores[2] = 2; lowerScores[3] = -3; /* Your solution goes here */...

  • IN MATLAB CHALLENGE ACTIVITY 25.5.1: For loops. Reset Write a for loop that prints from initialNumber...

    IN MATLAB CHALLENGE ACTIVITY 25.5.1: For loops. Reset Write a for loop that prints from initialNumber to finalNumber. Ex: initialNumber-3 and finalNumber 1 outputs 3 -2 -1 0 1 I #include <stdio.h> 3 int main(void) t 4 int initialNumber; 6 int i; int finalNumber; initialNumber--5 11 for 12 13 14 Your solution goes heref printf("%d ", i); return 161 17 5 Check Next

  • C programming only please 5.2.3: Printing array elements with a for loop. Write a for loop...

    C programming only please 5.2.3: Printing array elements with a for loop. Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print: 7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = NUM_VALS - 1. (Notes) Note: These activities may test code with...

  • Write a C Program that inputs an array of integers from the user along-with the length...

    Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...

  • CHALLENGE ACTIVITY 5.71 String library functions. Assign the size of userinput to stringSize. Ex: if userinput...

    CHALLENGE ACTIVITY 5.71 String library functions. Assign the size of userinput to stringSize. Ex: if userinput is 'Hello output is: Size of user Input: 5 1 #include <stdio.h> 2 #include <string.h> 4 int main(void) { char user Input[50]; int stringSize; BO scanf("%s", userInput); /* Your solution goes here" printf("Size of user Input: %d\n", stringsize); return ; Run

  • in java Feedback? CHALLENGE ACTIVITY 5.2.2: Printing array elements. Write three statements to print the first...

    in java Feedback? CHALLENGE ACTIVITY 5.2.2: Printing array elements. Write three statements to print the first three elements of array run Times. Follow each statement with a newline. Ex: If runTime = (800,775, 790, 805, 808) print: 800 775 790 Note: These activities will test the code with different test values. This activity will perform two tests, both with a 5 element array. See 'How to Use zyBooks". Also note: If the submitted code tries to access an invalid array...

  • 7.2.3: Printing array elements with a for loop. Write a for loop to print all elements...

    7.2.3: Printing array elements with a for loop. Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print: 7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = courseGrades.length - 1. (Notes) Also note: If the submitted code tries to access an invalid...

  • Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a...

    Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a comma and space. Ex: If hourlyTemp = {90, 92, 94, 95}, print: 90, 92, 94, 95 Your code's output should end with the last element, without a subsequent comma, space, or newline. import java.util.Scanner; public class PrintWithComma {    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       final int NUM_VALS = 4;       int[] hourlyTemp = new...

  • IN C PLEASE Find the maximum value and minimum value in miles Tracker. Assign the maximum...

    IN C PLEASE Find the maximum value and minimum value in miles Tracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample output for the given program: Min miles: -10 Max miles: 40 (Notes) 1 tes pass ㄷ Alltes int j; 1 #include <stdio.h> 2 3 int main(void) { 4 const int NUM_ROWS = 2; 5 const int NUM_COLS = 2; 6 int milesTracker [NUM_ROWS] [NUM_COLS]; 7 int i; 8 9 int maxMiles = 0; //...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT