165k views
3 votes
How can i print an art triangle made up of asterisks using only one line of code. Using string concatenation (multiplication and addition and maybe parenthesis)?

User Gakhov
by
3.1k points

1 Answer

5 votes

#include <iostream>

int main(int argc, char* argv[]) {

//One line

std::cout << "\t\t*\t\t\\\t\t\b* *\t\t\b\\\t\t\b\b* *\t\t\b\b\\\t\t\b\b\b* *\t\t\b\b\b\\\t\t\b\b\b\b* *\t\t\b\b\b\b\\\t\t\b\b\b\b\b* * * * * *\t\t\b\b\b\b\b\\";

return 0;

}

Yes, it is possible with a single line and using escape sequences, but it is tedious and not recommended. Instead, you can use loops to write more readable and easy on the eyes code. We only used the cout method (C++). Good luck!

How can i print an art triangle made up of asterisks using only one line of code. Using-example-1
User Taheera
by
4.1k points