Respuesta :
Answer:
- #include <iostream>
- using namespace std;
- int main()
- {
- const int NUM_VALS = 4;
- int hourlyTemp[NUM_VALS];
- int i;
- for (i = 0; i < NUM_VALS; ++i)
- {
- cin >> hourlyTemp[i];
- }
- /* Your solution goes here */
- for(i = 0; i < NUM_VALS; ++i){
- if(i < NUM_VALS -1){
- cout<<hourlyTemp[i]<<",";
- }
- else{
- cout<<hourlyTemp[i];
- }
- }
- cout << endl;
- return 0;
- }
Explanation:
The solution code is given from Line 18 - 26. To print the element from array one after another, we create a for loop to traverse through every element in the array (Line 18). Create an if condition to check if the current index i is not the last index, print the element followed with a comma (Line 20 -22). Otherwise print only the element (Line 23 - 25).
Answer:
for(i = 0; i < NUM_VALS; ++i){
if(i < NUM_VALS -1){
System.out.print(hourlyTemp[i] + ", ");
}
else{
System.out.print(hourlyTemp[i]);
}
}
Explanation:
