Help in C++ programming!

Status
Not open for further replies.

mayoorite

Night Fury
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
 
Last edited:

gk2k

gkbhat.blogspot.com
I cannot see any pattern in the file :( Post a snapshot of the pattern and what have u tried to solve it :)
 

SlashDK

MV VIP to the MAX
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

Sami Hyypiä, LFC legend
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.
 
OP
mayoorite

mayoorite

Night Fury
#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

Sami Hyypiä, LFC legend
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.
 
Last edited:

nims11

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

vickybat

I am the night...I am...
@ 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]
 
Last edited:

nims11

BIOS Terminator
Code:
for(int k=0;k<i;k++)
cout<<" ";

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

mayoorite

Night Fury
: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
 
Last edited:

gk2k

gkbhat.blogspot.com
@OP: Glad that you where able to solve it. You think that you cannot do something until you do it.
 
Status
Not open for further replies.
Top Bottom