New course! Every coder should learn Generative AI!
Try a free lesson0
Not get desired output in c++
#include <iostream> using namespace std; int main() { cout << " c \n"; cout << " + \n"; cout <<" + "; return 0; } Why I am not getting output which is C + + It is question from c++ course lesson 3
4 Answers
+ 4
#include <iostream>
using namespace std;
int main()
{
cout << "C\n";
cout << "+\n";
cout <<"+";
return 0;
}
I think you should remove the space and use a capital C.
+ 2
you really don't need all those cout. You can condense it to one line.
cout<<"C\n+\n+";
0
The issue with your code is that you are using the escape sequence `\n` after the second `" + "`, which is causing the next character to be printed on a new line. Here's the corrected code:
#include <iostream>
using namespace std;
int main()
{
cout << "C\n";
cout << "+\n";
cout << "+";
return 0;
}
Now, this should give you the desired output:
```
C
+
+
```
0
here is something to explore. Google 'iomanip setw()' and 'C++ for-each loop' to learn more...
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int tab = 10;
for(auto c : "PYTHON")
cout<<setw(tab)<<c<<'\n';
}