Kuwait:
After all this explanations and codes, it should be clear now!
I like the code Prelude wrote.
but I think the main() function should return a value, but it's realy nice.
Kuwait:
After all this explanations and codes, it should be clear now!
I like the code Prelude wrote.
but I think the main() function should return a value, but it's realy nice.
It's a matter of personal taste. I usually omit the return 0, in favor of code brevity. Both ways are vaild in ISO C++.Originally posted by ammar
I like the code Prelude wrote.
but I think the main() function should return a value, but it's realy nice.
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
use printf() if you must.
I like Prelude's code , but what does the (~n & k) test for?
Compilers:
GCC on Red Hat 8.1 (Primary)
GCC on Mac OS X 10.2.4 (Secondary)
Others:
MinGW on XP
Take the printf("\n"); out of the second inside for loop, and put it at the very end of the outside for loop. The rest (arguably) is up to you.Originally posted by SPiRiToFCaT
You want 10-i spaces before each line of stars right?Code:for(int i=1; i<=10; i++) { for(int k=10-i; k>0; k--) { printf(" "); } for(j=1; j<=i; j++) { printf("*"); printf("\n"); } }
so just print 10-i spaces. Meaning, print a space 10-i times.
~Inquirer, over and out.
Compilers:
GCC on Red Hat 8.1 (Primary)
GCC on Mac OS X 10.2.4 (Secondary)
Others:
MinGW on XP
thanx i understand now how to do it
thanx again
is this the way that you want??
*
**
***
****
*****
******
if so the code is this
Code:/* for(int i=1; i<=9; i++) { for(int k=10-i; k>0; k--) { printf(" "); } for(int j=1; j<=i; j++) { printf("*"); } printf("\n"); } */
That's new, I didn't know that you can ommit the return 0 in the int main() function.Originally posted by Sang-drax
It's a matter of personal taste. I usually omit the return 0, in favor of code brevity. Both ways are vaild in ISO C++.
Thanks for that.
Nested for-loops aren't neccessary:
EDIT:Code:for (int i=1;i<=10;++i) cout << setw(i) << setfill('*') << "" << endl;
Perhaps this is more what you want:
Code:for (int i=1;i<=10;++i) cout << setw(10-i)<<setfill(' ') << ""<< setw(i) << setfill('*') << "" << endl;
Last edited by Sang-drax; 10-31-2002 at 05:00 AM.
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling