Answer:
#include <iostream>
using namespace std;
int main() {
int NUM_VALS;//variable NUM_VALS for the size of the array..
cout<<"Enter the size of the array"<<endl;
cin>>NUM_VALS;//taking input the size of the array..
int hourlyTemp[NUM_VALS]; //declaring array hourlyTemp of size n..
cout<<"Enter values of the array "<<endl;
for(int i=0;i<NUM_VALS;i++)
cin>>hourlyTemp[i];//taking input of hourlyTemp
for(int i=0;i<NUM_VALS;i++) //for loop for iterating over the array..
{
if(i!=NUM_VALS-1)
cout<<hourlyTemp[i]<<", ";// print statement.
else
cout<<hourlyTemp[i];//print statement.
}
return 0;
}
Step-by-step explanation:
I have taken NUM_VALS variable for the size of the array hourlyTemp. First i am taking input the size of array form user and after that array elements are also entered by the user.I am iterating over the array using for loop and checking that it is not the last element if it is simply printing it if it is not then printing comma and space also.