46.2k views
2 votes
Write a program that prints the numbers 1 to 4 on the sameline with each pair of adjacent numbers separated by a single space(1 2 3 4). Print the numbers in the followingthree ways:

(a) Using one output statement with one streaminsertion operator.
(b) Using one output statement with four streaminsertion operators.
(c) Using four output statements.

User Herry
by
7.6k points

1 Answer

7 votes

Answer:

#include <iostream>

using namespace std;

int main() {

cout<<"Printing by method 1"<<endl;

//using 1 output statement with one streaminsertion operator.

cout<<"1 2 3 4";

cout<<endl<<"Printing by method 2"<<endl;

//using 1 output statement with four stream insertion operator.

cout<<"1 "<<"2 "<<"3 "<<"4";

cout<<endl<<"Printing by method 3"<<endl;

//using four output statements.

cout<<"1 ";

cout<<"2 ";

cout<<"3 ";

cout<<"4 ";

return 0;

}

Output:-

Printing by method 1

1 2 3 4

Printing by method 2

1 2 3 4

Printing by method 3

1 2 3 4

Step-by-step explanation:

The above code is as per the question given.All the three methods are implemented as per the question.

User Sastanin
by
7.6k points