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.
Printable View
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++.Quote:
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.
use printf() if you must.
I like Prelude's code :), but what does the (~n & k) test for?
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.Quote:
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.
:) 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.Quote:
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;