hi every one :rolleyes:
i m new in C++. and i am stuck in the programe please any body tell me what is the code of this pyramid of number.

The pyramid should look like this:

[IMG]http://www.daniweb.com/techtalkforums/attachment.php?attachmentid=2433&stc=1&d=1160907855[/IMG]


http://www.daniweb.com/techtalkforums/announcement8-2.html

hey comeon i already spend lot of time on it and also made a code but cant find any solution the problem is in the spaces which are not managed by me.. :sad:
here is the code tell me what is the problem with that

# include <iostream.h>
# include <conio.h>

int main()
{
int num;

wronginput:
cout << "\nEnter The Number Range {0..9}\n";
cin>> num;
if(num < 0 || num >9)
{
cout<<"\nPlease Enter The Number B/W {0..9}\n";
goto wronginput;
}
int f=1;
for(int i = num; i >= 1; i--)
{
for(int k = 1; k >= i ; k--)
cout <<" ";

for(int l = num ; l>=i;l--)
{
cout<<f;
}
cout<<endl;
f++;
}

getch();

return 0;
}

> the problem is in the spaces which are not managed by me
Well if you'd said that in the first instance, and posted what you had tried, there would be no need to get all uppity.

> for(int k = 1; k >= i ; k--)
k starts at 1 and decreases
How is this going to be >= i ?

Look at the shape - it has less spaces on each row and more numbers. Which of your for loops is counting downwards?
Use that value to work out how many spaces to print out.

It might help if you called your variables say

int rowNumber;
int numSpaces;
int numDigits;

rather than i, j, k.
Lower case 'l' is a very poor choice for a variable name, it is very hard to tell it from numeric 1

With meaningful names, it becomes pretty obvious if you're doing something dumb.

Hey thanks Salem yaar .... here is the correct code
:cheesy::cheesy: i know i again use the i k n type of variables :lol: next time i will try to chane my habbit thanks ....

#include <iostream.h>
#include <conio.h>
int main()
{

int i, k, n= 5;

wronginput:
cout << "\nEnter The Number Range {0..9}\n";
cin>> n;
if(n < 0 || n >9)
{
cout<<"\nPlease Enter The Number B/W {0..9}\n";
goto wronginput;
}


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

cout<<endl<<"Press any key to quit";
getch();
return 0;
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.