1. That code is severely obfuscated. Use [co
de] [/co
de] tags either by typing [co
de] <paste code here> [/co
de] or by clicking the # under the word
Format: on the right hand side of the screen and pasting your code after the [co
de] tag. See below for the result.
2. iostream.h is deprecated
3. You need to prefix cout with std:: to use it, or put "using namespace std;" at the top of the file, before "int main()"
4. Your line "for (i=5;i>=1;i--)" was doing the opposite of what it should have been doing. I changed it to "for (i = 1; i <= 5; ++i)" and it worked because the way you did it, it was decrementing i, not incrementing it.
5. Main needs to return a number. Place "return 0;" at the end of the function, just before the closing brace ('}').
6. You don't need to use endl; endl prints a newline and then flushes the buffer. You don't need to flush the buffer.
1 2 3 4 5 6 7 8 9 10 11 12
|
#include <iostream>
int main() {
int i,j;
for (i = 1; i <= 5; ++i) {
for (j = 1; j <= i; ++j) {
std::cout << i;
}
std::cout << "\n";
}
return 0;
}
|