2 array C program problems 1) An array has been defined as int vals[5] and all v
ID: 3564065 • Letter: 2
Question
2 array C program problems
1) An array has been defined as int vals[5] and all values initialized. Use a loop to count the number of element values between lowVal and highVal, inclusive. Assign the result to numValsInRange. Those variables are int types, already-defined and initialized. Use loop variable i, already defined as int. Example: If vals contains 10, 20, 55, 30, 50, and lowVal = 20 and highVal = 50, then 20, 30, and 50 are within the range, so assign 3 to numValsInRange.
Below, do not type an entire program. Only type the portion indicated by the above instructions.
2) An array has been defined as int vals[VALS_SIZE] and all values initialized. A loop variable i of type int is already defined. VALS_SIZE is type int and already-defined and initialized. Print the array elements on a single line, separating elements by a comma and space. Do NOT print a comma and space after the last element. Example for VALS_SIZE = 5 and vals containing 20, 30, 40, 50, and 60:
Below, do not type an entire program. Only type the portion indicated by the above instructions
Explanation / Answer
1) An array has been defined as int vals[5] and all values initialized. Use a loop to count the number of element values between lowVal and highVal, inclusive.
Assign the result to numValsInRange. Those variables are int types, already-defined and initialized. Use loop variable i, already defined as int.
Example: If vals contains 10, 20, 55, 30, 50, and lowVal = 20 and highVal = 50, then 20, 30, and 50 are within the range, so assign 3 to numValsInRange.
int numValsInRange=0;
for(i=0; i<5; i++){
if(vals[i]>=lowVal && vals[i]<=highVal)
numValsInRange++;
}
2) An array has been defined as int vals[VALS_SIZE] and all values initialized. A loop variable i of type int is already defined.
VALS_SIZE is type int and already-defined and initialized. Print the array elements on a single line, separating elements by a comma and space.
Do NOT print a comma and space after the last element. Example for VALS_SIZE = 5 and vals containing 20, 30, 40, 50, and 60:
20, 30, 40, 50, 60
for(i=0; i<VALS_SIZE; i++){
if(i==0)
printf("%d",vals[i]);
else
printf(", %d",vals[i]);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.