HOW TO MAKE THIS TRIANGLE

GUYS CAN SOMEONE HELP ME THROUGH THIS.

OUTPUT:
wwwwwww*
wwwwww**
wwwww***
wwww****
www*****
ww******
w*******
********


NOTE: (w)- represent as SPACE. i really do everythng but still i can't get this kind of output. so please guys i need your help. my Proffesor might give this kind of output for our finals. :))))))) TNX
Last edited on
On nth line there are 8-n spaces and n stars. That will be three for loops. There really isn't anything else to say. Maybe if you showed an effort, I could say what you did wrong.
@hamsterman

#include<iostream.h>
#include<conio.h>
main()
{
int x,y,z;

for(x=1;x<=5;x++)
{
for(y=5;y>=x;y--)
{
cout<<" ";
cout<<endl;
}
getch();
return 0;
}



NOTE: in this i code i can loop the spaces (w) as shown in my output above.
base on my knowledge. this problem has 3 for loops.(sorry for my grammar).the variable "z" is the one that i will put on the 3rd loop.


for( )
{
for( )
}
for( )
- just like this. but i really dont know what is the condition in the 3rd LOOP. i tried a lot to run it correctly.
so sir can u give me the exact code for the 3rd LOOP?. i really getting a hard time on this one. tnx a lot.
Last edited on
The second loop goes down from 5 to x (as you implemented it)
The third loop goes up from 0 to x (which is very much like the second loop just with ++ and <)
but am i right that this problem uses 3 for loops?. tnx a lot sir
one way to solve that is using 3 loops, yes. You're starting with 1 so: for(z=1;z<=x;z++)
@coder777
i can't really get the output. check this.


 #include<iostream.h>
#include<conio.h>
main()
{
int x,y,z;

for(x=1;x<=5;x++)
{
for(y=5;y>=x;y--)
{
cout<<" ";
cout<<endl;
}
for(z=1;z<=x;z++)
{
cout<<"*";
cout<<endl;
}
getch();
return 0;
}

output




*
*
*
*
*
* 




- idk why i cant get the output. i think there s a problem in executing
{ and  }
. sir can you point me my errors?. sorry i really need this xD
Last edited on
remove the cout<<endl; from the first loop and move that line from the third loop to after the third loop.

And use code tags: [code]Your code[/code] (When you edit you see 'Format:' on the right: press the <> button)
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream.h>
#include<conio.h>

main()
{
    int x,y,z;

    for(x=1;x<=5;x++)
    {
        for(y=5;y>=x;y--)
        {
            cout<<" ";
            cout<<endl;   // this prints a newline character--you want only 1 of these per line (at the end)
        }
        for(z=1;z<=x;z++)
        {
            cout<<"*";
            cout<<endl;
        }
    }            // this was missing
    getch();
    return 0;
}
Last edited on
@code777
output:

1
2
3
4
5
6
              *
*
*
*
*
*


Last edited on
Getting closer... Just think about the output you want (character by character) and make the program output that. Remember, 1 newline per line of output.

Here's a nice way to think of the outer loop:
 
    for(x=1;x<=5;x++)   // read this as, "for each line" 
Last edited on
@moorecm

output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
*
*


*
*
*

*
*
*
*

*
*
*
*
*



- im using turbo C++ IDE. anything wrong. :(
Show your code. And yes there's a } missing to close the first for loop
my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream.h>
#include<conio.h>
main()
{
int x,y,z;

for(x=1;x<=5;x++)
{
   for(y=5;y>=x;y--)
{
cout<<" ";
cout<<endl;
 }
   for(z=1;z<=x;z++)
 {
cout<<"*";
cout<<endl;
    }
}
getch();
return 0;
}



can u guys trace the problem???. i know how the 1st loop and 2nd loop functions. but my real problem is the 3rd for loop. im getting stucked in here.
Last edited on
What moorecm and I trying to say:

remove line12
remove line17

add before line 19 (the closing } of the first loop) cout<<endl;
Last edited on
@MOORCEM
@CODE777

I GOT IT
TNX A LOT GUYS. I LOVE YOU ALL. :)))
Topic archived. No new replies allowed.