Question

Double any element's value that is less than minVal. Ex: If minVal = 10, then dataPoints...

Double any element's value that is less than minVal. Ex: If minVal = 10, then dataPoints = {2, 12, 9, 20} becomes {4, 12, 18, 20}.

#include <stdio.h>

int main(void) {

const int NUM_POINTS = 4;

int dataPoints[NUM_POINTS];

int minVal;

int i;

dataPoints[0] = 2;

dataPoints[1] = 12;

dataPoints[2] = 9;

dataPoints[3] = 20;

minVal = 10;

/* Your solution goes here */

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

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

}

printf("\n");

return 0;

}

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

C Program:

#include <stdio.h>

int main(void) {

const int NUM_POINTS = 4;

int dataPoints[NUM_POINTS];

int minVal;

int i;

dataPoints[0] = 2;

dataPoints[1] = 12;

dataPoints[2] = 9;

dataPoints[3] = 20;

minVal = 10;

for(i=0; i<NUM_POINTS; i++)

{

if(dataPoints[i] < minVal)

dataPoints[i] = 2*dataPoints[i];

}

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

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

}

printf("\n");

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Double any element's value that is less than minVal. Ex: If minVal = 10, then dataPoints...
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
  • In the C language Double any element's value that is less than controlVal. Ex: If controlVal...

    In the C language Double any element's value that is less than controlVal. Ex: If controlVal = 10, then dataPoints = {2, 12, 9, 20} becomes {4, 12, 18, 20}. #include <stdio.h> int main(void) { const int NUM_POINTS = 4; int dataPoints[NUM_POINTS]; int controlVal; int i; scanf("%d", &controlVal); for (i = 0; i < NUM_POINTS; ++i) { scanf("%d ", &(dataPoints[i])); } /* Your solution goes here */ for (i = 0; i < NUM_POINTS; ++i) { printf("%d ", dataPoints[i]); }...

  • Double any element's value that is less than minValue. Ex: If minValue 10, then dataPoints =...

    Double any element's value that is less than minValue. Ex: If minValue 10, then dataPoints = {2, 12, 9, 20) becomes {4, 12, 18, 20). public static void main (String ] args) { Scanner scnr = new Scanner(System.in); 4 5 final int NUM_POINTS = 4; int dataPoints = int minValue int i new int[NUM POINTS]; 7 8 minValue 10 scnr.nextInt(); 11 for (i 0; i dataPoints[i] } dataPoints.length; ++i) { scnr.nextInt); 12 13 14 15 /Your solution goes here */...

  • in C++ Problem: Subtract 4 to any element's value that is greater than maxVal. Ex: If...

    in C++ Problem: Subtract 4 to any element's value that is greater than maxVal. Ex: If maxVal = 10, then dataPoints = {2, 12, 9, 20} becomes {2, 8, 9, 16}. ------------------------ #include #include using namespace std; int main() { int maxVal; int NUM_POINTS; unsigned int i; cin >> maxVal; cin >> NUM_POINTS; vector dataPoints(NUM_POINTS); for (i = 0; i < dataPoints.size(); ++i) { cin >> dataPoints.at(i); } /* Your solution goes here */ for (i = 0; i <...

  • For any element in keysList with a value greater than 50. print the corresponding value in...

    For any element in keysList with a value greater than 50. print the corresponding value in itemsList, followed by a comma (no spaces) Ex: If the input is 32 105 101 35 10 20 30 40 the output is 20,30, 1 include <stdio.h> 2 3 int main(void) { 4 const int SIZE LIST - 4 5 int keysList[SIZE LISTI: 6 int itemslist[SIZE_LIST); 7 int 1; 8 9 scanf("%d", &keysList[0]); 10 scanf("%d", &keyslist[1]); 11 scanf("%d", &keysList[2]); 12 scanf("%d", &keysList[]); 13 14...

  • for c CHALLENGE ACTIVITY 9.7.1: Decrement array elements. Write a loop that subtracts 1 from each...

    for c CHALLENGE ACTIVITY 9.7.1: Decrement array elements. 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). 1 include <stdio.h> 3 int main(void) 0 const int SCORES_SIZE - 4; int lowerScores [SCORES_SIZE]: int i; for (1 - 0; i < SCORES_SIZE; ++) { scanf("%d", &(lowerScores[i])); /" Your solution goes here / { 15 for (i = 0; i...

  • C - Language Write a loop that sets each array element to the sum of itself...

    C - Language Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the same. Be careful not to index beyond the last element. Ex: Initial scores: 10, 20, 30, 40 Scores after the loop: 30, 50, 70, 40 The first element is 30 or 10 + 20, the second element is 50 or 20 + 30, and the third element is 70 or 30 +...

  • coding in C Programming Assign the size of userInput to stringSize. Ex: if userInput = "Hello",...

    coding in C Programming Assign the size of userInput to stringSize. Ex: if userInput = "Hello", output is: Size of userInput: 5 #include < stdio.h > #include < string.h > int main(void) { char userlnput[50] = "": int stringSize = 0: strcpy(userInput, "Hello"): /* Your solution goes here */ printf("Size of userlnput: %d\n", stringSize): return 0: }

  • 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 C please Write a function so that the main() code below can be replaced by...

    In C please Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original maino: int main(void) { double milesPerHour, double minutes Traveled; double hours Traveled; double miles Traveled; scanf("%f", &milesPerHour); scanf("%lf", &minutes Traveled); hours Traveled = minutes Traveled / 60.0; miles Traveled = hours Traveled * milesPerHour; printf("Miles: %1f\n", miles Traveled); return 0; 1 #include <stdio.h> 3/* Your solution goes here */ 1 test passed 4 All tests passed...

  • 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