problem in pyramid

hello,
I wanted to make a pyramid like this:-
____*
___*_*
__*___*
_*_____*
*********

for n=5.
the lines are not underscores but spaces.

My try:-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  #include <iostream.h>
  void main()
  { int i,k,l,n;
  cin>>n;
for(i=1; i<=n-1; i++)
{
for(k=1; k<=i; k++)
{if((k==n+i-1)||(k==n-i+1))
cout<<"*";
else
cout<<" ";
}
cout<<"\n";
}
for(l=1; l<=2*n-1; l++)
cout<<"*";
}


But the output comes as:-
__ *
_*


*********
Note: This is a turbo c++ program.
Last edited on
 
if((k==n+i-1)||(k--n-i+1))


I assume you meant
 
if((k==n+i-1)||(k==n-i+1))
@abhishekm71: yes,
thanks
please someone answer the question
 
for(k=1; k<=i; k++)


This only prints part of the pyramid.

Change it to:
 
for(k=1; k<=n; k++)


Also you may need to check and revise the "if conditions".
Last edited on
Topic archived. No new replies allowed.