Question

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]);
}
printf("\n");

return 0;
}

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

#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]));
}
  
//if the dataPoint value is less than controlVal then double it
for (i = 0; i < NUM_POINTS; ++i)
{
if(dataPoints[i]<controlVal)
{
dataPoints[i] = 2 * dataPoints[i];
}
}

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

INPUT:

OUTPUT:

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

  • 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 +...

  • I need the programming to be in language C. I am using a program called Zybook...

    I need the programming to be in language C. I am using a program called Zybook Prompt: Write a statement that outputs variable numObjects. End with a newline. Given: #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); return 0; } What I did so far. I am not sure if its right tho? #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); printf(" num Objects is "); printf("%d\n", userAge); return 0; }

  • 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...

  • Translate the following C program to Pep/9 assembly language. #include <stdio.h> const int limit = 5;...

    Translate the following C program to Pep/9 assembly language. #include <stdio.h> const int limit = 5; int main() { int number; scanf("%d",&number); while (number < limit){ number++; printf("%d",number); } 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

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