Translate

Write a program that prints the numbers 1 to 4 on the same line


Question:
Write a program that prints the numbers 1 to 4 on the same line with each pair of adjacent numbers separated by one space.
Write the program using the following methods:
a) Using one output statement with one stream insertion operator.
b) Using one output statement with four stream insertion operators.
c) Using four output statements.

Answer


#include <iostream>
using namespace std;

int main ()
 {
 // Part A
 cout << "1 2 3 4\n";

 // Part B
 cout << "1 " << "2 " << "3 " << "4\n";

 // Part C
 cout << "1 ";
 cout << "2 ";
 cout << "3 ";
 cout << "4" << endl;

 return 0;
 }

No comments:

Post a Comment