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...

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

Edited 6 Years Ago by Lerner: n/a

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

This article has been dead for over six months. Start a new discussion instead.