# Help in C++ programming!



## mayoorite (Sep 9, 2011)

HI!
 I NEED C++ CODING TO MAKE A PATTERN USING NESTED LOOP.
 I HAVE ATTACHED THE TEXT FILE  FOR PATTERN.
PLEASE HELP ITS URGENT!!
*www.mediafire.com/imgbnc.php/af15cf1d5d30d01d3fbf551e948fcb5a8b684f1ee9f6d700bb77bcdc7be5a3266g.jpg


----------



## gk2k (Sep 9, 2011)

I cannot see any pattern in the file  Post a snapshot of the pattern and what have u tried to solve it


----------



## SlashDK (Sep 9, 2011)

This ones pretty easy. First make a loop for the spaces at the left (i=0;i<=4;i++) and inside it make another loop for "& " (j=4;j>=0;j--).


----------



## Liverpool_fan (Sep 9, 2011)

12 hours you have to post your own attempt, doesn't matter it works or not but an honest attempt must be seen. Otherwise thread will be locked. No hand helding solutions, those posts will be deleted.


----------



## mayoorite (Sep 9, 2011)

#include<iostream.h>
#include<conio.h>
main()
{
	clrscr();
	int i,j;
	for(i=0;i<=4;i++)
       {		for(j=4;j>=i;j--)
		cout<<" &";
		cout<<endl;
       }
       getch();
}
*www.mediafire.com/imgbnc.php/b193d8b89be15353674b5048b230ec526f534471615729c98b55c2b90df3dd116g.jpg
I don`t know how to increase 1 space in every loop.
please help!


----------



## Liverpool_fan (Sep 9, 2011)

Try running a parallel inner loop which prints increasing amount of spaces (or tabs) with each increasing iteration. That  is before the inner loop '&' executes, another loop executes which prints spaces ahead of it.


----------



## nims11 (Sep 9, 2011)

add a *for* loop before the *for* loop that prints the '&' to print number of spaces according to *i*.


----------



## vickybat (Sep 9, 2011)

*@ mayoorite*

Check the following buddy. Its prints a reverse equilateral triangle according to your needs.


```
[B]#include<iostream>

using namespace std;

 

int main()

{

int n,i,space,column;

char a= '&';

cout<<"Enter the number of rows: "<<endl;

cin>>n;

 

for(i=n;i>0;i--)

      {

      for(space=0;space<n-i;space++)cout<<" "; [COLOR="Blue"]//assigning spaces[/COLOR]

          cout<<a<<" "; [COLOR="Blue"]//Writing the "&" character after assigning spaces[/COLOR]

          for(column=i-1;column>0;column--)cout<<a<<" "; [COLOR="Blue"]//writing the "&" character in the columns
[/COLOR]
          cout<<endl;

          }
          
    cin.ignore();
     cin.get();

return 0;

}[/B]
```


----------



## mayoorite (Sep 9, 2011)

can anyone please write the code.
i am a beginner and have learned loops yesterday.


----------



## nims11 (Sep 9, 2011)

```
for(int k=0;k<i;k++)
cout<<" ";
```

simply add this line just before the 2nd *for* loop of your program.


----------



## mayoorite (Sep 9, 2011)

THANKS TO ALL FINALLY I GOT THE CORRECT WAY .
I HAVE USE THE BELOW CODE FOR IT.

```
#include<iostream.h>
#include<conio.h>
main()
{
	clrscr();
	int i,j,k,n;
	cout<<"Enter rows:";
	cin>>n;
	for(i=0;i<=n-1;i++)
       {		
		for(k=0;k<=i;k++)
		cout<<" ";
		for(j=n-1;j>=i;j--)
		cout<<" &";
		cout<<endl;
       }
       getch();
}
```
LOOP->*img225.imageshack.us/img225/8844/finallv.png


----------



## vickybat (Sep 9, 2011)

^^ Good job buddy. Keep practicing. C++ is very very interesting.


----------



## gk2k (Sep 10, 2011)

@OP: Glad that you where able to solve it. You think that you cannot do something until you do it.


----------



## Liverpool_fan (Sep 10, 2011)

I guess the thread has run its course.


----------

