Answer to Question #302917 in C++ for Vikas

Question #302917

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


1
Expert's answer
2022-02-26T05:51:38-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog