allenevaalleneva@gmail.com wrote:
Quote:
Q:Write a program that prints the numbers 1 to 4 on the same line with
with each pair of adjacent numbers separated by one space. Do this
several ways:
a) Using one statement with one stream insertion operator.
b) Using one statement with four stream insertion operators.
c) Using for statement
>
my answers are as follow
>
a)
{
std::cout << "1 2 3 4";
system("PAUSE");
return 0;
}
>
>
>
b)
{
std::cout << "1" << " 2" << " 3" << " 4";
system("PAUSE");
return 0;
}
>
>
>
c)
{
std::cout << "1";
cout << " 2";
cout << " 3";
cout << " 4";
system("PAUSE");
return 0;
}
>
>
i don't know this answer is right or not
if right
how can be more simple for this question?
>
None of your answers are correct, since none of them are programs.
You are missing main, you are missing the necessary #includes for
std::cout and operator<<(std::ostream&,const char *).
In addition, I believe (but I can't find chapter&verse) that if you
don't flush/endl an ostream, your output is undefined -- you may not see
anything.