Pyramid Help

Pages: 12
It shows up in full size on the preview, and even if it didn't I could always copy+paste it into a normal-size text box.

Gee. Now I really feel rotten.

-Albatross
.....................................................................................................................................................lo siento, Albatross. At least you're not the forum troll.
Last edited on
Gee. Now I really feel rotten.


We love our forum police =]
#include<iostream.h>
#include<conio.h>
void main()
{
int n;
cin>>n; //enter the no. of line to print
clrscr();
for(int i=0;i<n;i++) // 1st loop for new line print
{
for(int j = n-1;j>i;j--) // 2nd loop for space " " print
cout<<" ";
for(int k=0;k<=i;k++) // 3rd loop for left side triangle print
cout<<"*";
for(int m= 0;m<i;m++) // 4th loop for right side triangle print
cout<<"*";
cout<<"\n";
}
getch();
}

"simple as possible"
[code] "Please use code tags" [/code]
main must return int
#include <iostream> not .h
There is no actual need for conio

By the way, do you use Turbo C as compiler?
Thank you so much you all for your reply.arun thakur's code is very useful and simple.thanks
Now I need this output using simple loops.


*
***
*****
*******
*
***
*****
*******
*
***
*****
*******
*
***
*****
*******
Do you see any relation between
   *
  ***
 *****
*******

and
   *
  ***
 *****
*******
   *
  ***
 *****
*******
   *
  ***
 *****
*******

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream.h>
#include<conio.h>
 void main()
{
int n;
cin>>n;
clrscr();
for(int h=1;h<=4;h++) //------loop for printing pattren
for(int i=0;i<n;i++)
{
	for(int j = n-1;j>i;j--)
	cout<<" ";
	for(int k=0;k<=i;k++)
	cout<<"*";
	for(int m= 0;m<i;m++)
	cout<<"*";
	cout<<"\n";
}
getch();
}


u can also do it using function calling...
thank you arun.but how can i do it using function give me details
closed account (zwA4jE8b)
i finally got it..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

int main()
{
	int i, j, k, r;
	r = 4;

	for (i = 1; i <= r; i++)
	{
		for (j = r; j > i; j--)
			cout << " ";
		for (k = 1; k <= ((i * 2) - 1) ;k++)
			cout << "*";
		cout << endl;
	}

	cin.get();
	return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream.h>
#include<conio.h>
 void main()
{

int i,j,k;

for(i=0;i<4;i++)
{
	for(j=3;j>i;j--)
		cout<<" ";
	for(k=0;k<=i+j;k++)
		cout<<"*";
	cout<<"\n";
}
 }

this is my code.it is very simple.
Those pyramids have nice symmetry.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream.h>
#include<conio.h>
#include<dos.h>
void pattern(int m,int n) /*----function definition with formal arguments.---m for no. of pattrens and n for number of lines.
				we can also take a,b,c,...z as formal arguments it does't matter */
{
for(int h=1;h<=m;h++)
for(int i=0;i<n;i++)
{
	for(int j = n-1;j>i;j--)
	{
	cout<<" ";}
	for(int k=0;k<=i;k++)
      {
	delay(150);    //-----------just for fun i use delay function dude...
	cout<<"*";
      }
	for(int m= 0;m<i;m++)
      {
	delay(150);
	cout<<"*";
      }
	cout<<"\n";
}
}

void main(void)
{
int  m,n;
clrscr();
cout<<"enter no. of patterns : ";
cin>>m;
cout<<"\nenter no.of lines to print : ";
cin>>n;
pattern(m,n);     //function call...with actual arguments....
getch();
}

i create a function called "pattern" with args. m and n..u can take any name for arguments...it hardly mattres...
i use delay function from dos preproccesor directive...delay (100); means delay of 100 ms.
i like the way i did it in C# more :)

substrings my friends :o
Topic archived. No new replies allowed.
Pages: 12