 |
09-09-2011, 02:43 PM
|
#1 (permalink)
|
|
Night Fury
Join Date: Jun 2011
Location: Ajmer,Rajasthan
Posts: 99
|
Help in C++ programming!
HI!
I NEED C++ CODING TO MAKE A PATTERN USING NESTED LOOP.
I HAVE ATTACHED THE TEXT FILE FOR PATTERN.
PLEASE HELP ITS URGENT!!
Last edited by mayoorite; 09-09-2011 at 04:07 PM.
|
|
|
|
Advertisements. Register and be a member of the community to get rid of them.
|
|
Advertisement
|
|
09-09-2011, 03:17 PM
|
#2 (permalink)
|
|
gkbhat.blogspot.com
Join Date: Apr 2008
Location: Mangalore/Bangalore
Posts: 103
|
Re: Help in C++ programming!
I cannot see any pattern in the file  Post a snapshot of the pattern and what have u tried to solve it
__________________
blogging at http://gkbhat.blogspot.com
|
|
|
09-09-2011, 05:10 PM
|
#3 (permalink)
|
|
The Assassin
Join Date: May 2010
Location: Delhi
Posts: 620
|
Re: Help in C++ programming!
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--).
|
|
|
09-09-2011, 07:36 PM
|
#4 (permalink)
|
|
Sami Hyypiä, LFC legend
Join Date: Jun 2007
Location: Нью-Дели
Posts: 2,138
|
Re: Help in C++ programming!
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.
|
|
|
09-09-2011, 08:08 PM
|
#5 (permalink)
|
|
Night Fury
Join Date: Jun 2011
Location: Ajmer,Rajasthan
Posts: 99
|
Re: Help in C++ programming!
#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();
}

I don`t know how to increase 1 space in every loop.
please help!
|
|
|
09-09-2011, 08:12 PM
|
#6 (permalink)
|
|
Sami Hyypiä, LFC legend
Join Date: Jun 2007
Location: Нью-Дели
Posts: 2,138
|
Re: Help in C++ programming!
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 by Liverpool_fan; 09-09-2011 at 08:19 PM.
Reason: Misunderstood ther question
|
|
|
09-09-2011, 08:18 PM
|
#7 (permalink)
|
|
BIOS Terminator
Join Date: Apr 2008
Location: Ranchi
Posts: 816
|
Re: Help in C++ programming!
add a for loop before the for loop that prints the '&' to print number of spaces according to i.
|
|
|
09-09-2011, 08:54 PM
|
#8 (permalink)
|
|
I am the night! I am....
Join Date: Aug 2009
Location: Gotham City
Posts: 4,209
|
Re: Help in C++ programming!
@ mayoorite
Check the following buddy. Its prints a reverse equilateral triangle according to your needs.
Code:
#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<<" "; //assigning spaces
cout<<a<<" "; //Writing the "&" character after assigning spaces
for(column=i-1;column>0;column--)cout<<a<<" "; //writing the "&" character in the columns
cout<<endl;
}
cin.ignore();
cin.get();
return 0;
}
__________________
core i5 750, biostar h55 A+ (X16+X4), 4gb 1333 ddr3, corsair vx450, cm elite 335,Asus EAH 5750 FORMULA , samsung 2033 sw plus, wd green 1tb , wd 1tb my book , hp dvd writer,Apc 650 va, logitech z313
Last edited by vickybat; 09-09-2011 at 08:59 PM.
|
|
|
09-09-2011, 08:58 PM
|
#9 (permalink)
|
|
Night Fury
Join Date: Jun 2011
Location: Ajmer,Rajasthan
Posts: 99
|
Re: Help in C++ programming!
can anyone please write the code.
i am a beginner and have learned loops yesterday.
|
|
|
09-09-2011, 09:24 PM
|
#10 (permalink)
|
|
BIOS Terminator
Join Date: Apr 2008
Location: Ranchi
Posts: 816
|
Re: Help in C++ programming!
Code:
for(int k=0;k<i;k++)
cout<<" ";
simply add this line just before the 2nd for loop of your program.
|
|
|
09-09-2011, 10:06 PM
|
#11 (permalink)
|
|
Night Fury
Join Date: Jun 2011
Location: Ajmer,Rajasthan
Posts: 99
|
Re: Help in C++ programming!
 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-> 
Last edited by mayoorite; 09-09-2011 at 10:04 PM.
|
|
|
09-09-2011, 10:49 PM
|
#12 (permalink)
|
|
I am the night! I am....
Join Date: Aug 2009
Location: Gotham City
Posts: 4,209
|
Re: Help in C++ programming!
^^ Good job buddy. Keep practicing. C++ is very very interesting.
__________________
core i5 750, biostar h55 A+ (X16+X4), 4gb 1333 ddr3, corsair vx450, cm elite 335,Asus EAH 5750 FORMULA , samsung 2033 sw plus, wd green 1tb , wd 1tb my book , hp dvd writer,Apc 650 va, logitech z313
|
|
|
10-09-2011, 12:53 AM
|
#13 (permalink)
|
|
gkbhat.blogspot.com
Join Date: Apr 2008
Location: Mangalore/Bangalore
Posts: 103
|
Re: Help in C++ programming!
@OP: Glad that you where able to solve it. You think that you cannot do something until you do it.
__________________
blogging at http://gkbhat.blogspot.com
|
|
|
10-09-2011, 07:52 AM
|
#14 (permalink)
|
|
Sami Hyypiä, LFC legend
Join Date: Jun 2007
Location: Нью-Дели
Posts: 2,138
|
Re: Help in C++ programming!
I guess the thread has run its course.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|