1. triangle of *

hello,
how can i get an o/p that's basically if i/p is 4
then o/p should be
*
**
***
****
using for loop
ican get only one * per line
so how can i get o/p in reqd format

2. deja vu. this homework assignment shows up quite often.

Think counter.... think spitting out the number of asterisks that is in your counter.... think incrementing the counter each loop iteration.

That is all. I hope nobody gives you any code.

3. tri of*

hey iam not asking for code: afer here iam kind of cofused. how can i have multiple * is what iam struck at
# include <iostream.h>
main()
{
int n ,i;
cout<<"enter pos no";
cin>>n;
for ( i=1;i<=n;i++)
cout<<"*";
}
return 0;
}

4. ok, so I imagine what you are seeing is n stars. This is because you are drawing one star per iteration. But what you want to do is drop down a line each iteration right? you know how to do that I assume. plus... each iteration needs to draw "i" stars. another loop inside maybe? understand where I'm going?

5. tri of*

thank you for the tip.i got the o/p
Code:
```# include <iostream.h>
main()
{
int n ,i,j;
cout<<"enter pos no";
cin>>n;
for ( i=1;i<=n;i++)
{
for ( j=1;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}

return 0;
}```

6. glad to hear it. I wasn't attacking you're post by the way. I just wanted to head anyone else off who might post the code.

also, use code tags and your code will keep its indenting.

7. Query reg return 0

hello,
i waswondering why do we need to add the return 0 at the end of each prg. why warning is generated if this is not used and what is difference if we use void in the main function
void main (void) and void main()

8. ANSI standard main returns an int. What does this mean to the system? very little. void works in many compilers but some people and some compilers stick to the ANSI standard religiously.

9. if figuring out that type of puzzle provided a sense of accomplishment, you can further challenge yourself by trying to display the triangle as an isosoles(sp?) triangle (2D pyramid), and once you have that figured out try to draw a diamond shape. It is easier/prettier if you use only an odd number of * per row for these shapes.

10. Or prelude's fractal triangle

I would still like to see that code again, i can't find it anymore.. Links anyone?

~Inquirer

11. >I would still like to see that code again, i can't find it anymore.. Links anyone?
It was probably something like this:
Code:
```#include <iostream>

int main()
{
int i, j;

for ( i = 0; i < 16; i++ ) {
for ( j = 0; j <= i; j++ )
std::cout.put ( ~i & j ? ' ' : '1' );

std::cout.put  ( '\n' );
}

return 0;
}```
-Prelude

12. >It was probably something like this:
Actually, it was exactly like this...
Code:
```#include <iostream>

const int N = 16;

int main ()
{
for ( int n = 0; n < N; ++n ) {
for ( int k = 0; k <= n; ++k )
std::cout.put ( ( ~n & k ) ? ' ' : '*' );

std::cout.put ( '\n' );
}

std::cin.get();
}```
(I liked it, too. )

-Skipper

13. tri of*

hello,
i would like to try that right angle triangle and also prelude's fractal triangle
how should the o/p look like ?
thanx

14. This question didn't get answered last time:
>> What exactly does "( ~n & k )" test for?

Thanks!
~Inquirer

15. Since this is Prelude's code, she can feel free to yell at me...not really...but let's take a shot.
Code:
`std::cout.put ( ( ~n & k ) ? ' ' : '*' );`
'~' inverts the bits of a given value, in this case, 'n'. ('~' is typically used in a destructor.)

(You can see where this is going already, can't you?)

The bit values of 'n' are inverted then 'AND'ed against the bits of 'k'. Both must be '1' for the AND expression to evaluate the bit to '1', otherwise the bit evaluates to '0'.

Ex.:

n = 0001
~n = 1110

k =0101, therefore,

~n & k = 0100

The rest is semi-self-explanatory (I think that's a new word ). If the value of (~n & k) is '0' (false), we print an asterisk. If any of the bits evaluate to '1', the value is "true" - for those extremely new to the language, anything other than '0' is "true" - and we print a space character.

Play with it on paper to really convince yourself. Note that when the inner loop has completed, we go to the next line.

(Danged if I know how that young lady figured this out, though. )

-Skipper