My only problem is the spacing..... to make it right.... i need to make it inverted pyramid pattern...
like this:

9 8 7 6 5 4 3 2 1
 9 8 7 6 5 4 3 2
  9 8 7 6 5 4 3
   9 8 7 6 5 4
    9 8 7 6 5
     9 8 7 6
      9 8 7
       9 8
        9
#include <iostream.h>
#include <string.h>
#include <conio.h>
main()
{
clrscr();
	int num,n;
	cout<<"enter:";
	cin>>n;
	num=0;
	while (num !=n)
	{
	 for(int i = n; i >  num;--i)
		 {
		cout << " " << i;
		 }
	 cout << endl<<"  ";
	 if(num == 0)
	 cout<<" ";
	++num;
	}
	getch();
}

this is my code and only thing that wrong is the spacing before the rows...

Recommended Answers

All 2 Replies

Use an outer while loop to control the number of line. Within the outer while loop use two loops in sequential manner. The first inner loop will control the number of spaces to print for the line you are on. The second inner loop will print the sequence of numbers necessary for the line you are on.

line loop
   space loop
   numbers loop

My only problem is the spacing..... to make it right.... i need to make it inverted pyramid pattern...
like this:
this is my code and only thing that wrong is the spacing before the rows...

If I have understood you correctly you have an unwanted space at
the start of each line and that comes from your for loop.

#include <iostream.h>
#include <string.h>
#include <conio.h>
main()
{
clrscr();
	int num,n;
	cout<<"enter:";
	cin>>n;
	num=0;
	while (num !=n)
	{
	 for(int i = n; i >  num;--i)
		 {
		cout << " " << i;

You are outputting the first space here
if you:

//although cout << i << " "; should work
cout << i;
if(i != num + 1)
{
cout << " ";
}

other spaces might want adjusting too

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.