DIGIT-ARC read-only archive · snapshot: July 23, 2026

Help in C++ programming!

14 posts · originally from https://geek.digit.in/community/threads/help-in-c-programming.146236/

mayoorite
mayoorite Original post #1
Sep 9, 2011 at 2:43 PM
HI!
I NEED C++ CODING TO MAKE A PATTERN USING NESTED LOOP.
I HAVE ATTACHED THE TEXT FILE FOR PATTERN.
PLEASE HELP ITS URGENT!!:wave:
*www.mediafire.com/imgbnc.php/af15cf1d5d30d01d3fbf551e948fcb5a8b684f1ee9f6d700bb77bcdc7be5a3266g.jpg
G
gk2k #2
Sep 9, 2011 at 3:17 PM
I cannot see any pattern in the file :( Post a snapshot of the pattern and what have u tried to solve it :)
SlashDK
SlashDK #3
Sep 9, 2011 at 5:10 PM
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 at 7:36 PM
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 at 8:08 PM
#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 at 8:12 PM
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
nims11 #7
Sep 9, 2011 at 8:18 PM
add a for loop before the for loop that prints the '&' to print number of spaces according to i.
vickybat
Sep 9, 2011 at 8:54 PM
@ mayoorite

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

Code:
[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 at 8:58 PM
can anyone please write the code.
i am a beginner and have learned loops yesterday. :!:
nims11
nims11 #10
Sep 9, 2011 at 9:24 PM
Code:
for(int k=0;k<i;k++)
cout<<" ";

simply add this line just before the 2nd for loop of your program.
mayoorite
mayoorite #11
Sep 9, 2011 at 10:06 PM
:goodjob:THANKS TO ALL FINALLY I GOT THE CORRECT WAY .
I HAVE USE THE BELOW CODE FOR IT.
Code:
#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->:mallet:*img225.imageshack.us/img225/8844/finallv.png
vickybat
vickybat #12
Sep 9, 2011 at 10:49 PM
^^ Good job buddy. Keep practicing. C++ is very very interesting.
G
gk2k #13
Sep 10, 2011 at 12:53 AM
@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 at 7:52 AM
I guess the thread has run its course.