First, read in an input value for variable numVals. Then, read numVals integers from input and output each on the same line with the character ", " between each value. End with a newline.
Note: ", " should not be at the beginning or end of the output.
Ex: If the input is 4 -60 -35 -15 -45, the output is:
-60, -35, -15, -45
#include <iostream>
#include <string>
using namespace std;
int main()
{
int numVal;
cout << "Input: ";
cin>> numVal;
string* numbers=new string[numVal];
for (int i = 0; i < numVal; i++)
{
cin >> numbers[i];
}
for (int i = 0; i < numVal; i++)
{
if(i== numVal-1)
cout<<numbers[i];
else
cout << numbers[i] << ",";
}
delete[] numbers;
}
Comments
Leave a comment