First, read in an input value for variable numInput. Then, read numInput 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 -40 -30 -100 40, the output is:
-40: -30: -100: 40
#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