Hello I'm a newbie c++ student, I would like to ask how can I get this kind of program output by using c++:

10 10 10 10 10 10 10 10 10 10
9 9 9 9 9 9 9 9 9
8 8 8 8 8 8 8 8
7 7 7 7 7 7 7
6 6 6 6 6 6
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1

and this:

1 2 3 4 5
2 3 4 5
3 4 5
4 5
5

pls help me coding this.. any code using while, for, else or if.. thx for those who can help me.. thanks in advance..

So what have you managed to achieve so far (apart from not reading the introductory threads at the top of the forum).

We're here to help, not give you answers right off the bat.

sorry for that.. i programmed the second one with this code..

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

int main()
{
int x, n=0;
clrscr();
            for(x=1;x<=5;x++)
            cout << " " << x;
      if(++n==5)
      {
        cout << " " << endl;
      }
            n=0;
            for(x=2;x<=5;x++)
            cout << " " << x;
      if(++n==4)
      {
        cout << " " << endl;
      }
        n=0;
            for(x=3;x<=5;x++)
            cout << " " << x;
      if(++n==3)
      {
        cout << " " << endl;
      }

        n=0;
            for(x=4;x<=5;x++)
            cout << " " << x;
      if(++n==2)
      {
        cout << " " << endl;
      }
        n=0;
        for(x=5;x<=5;x++)
        cout << " " << x;
    }
getch();
return 0;
}

is there any way to make it shorter? i think this is too long.. can u help me?

Edited 3 Years Ago by mike_2000_17: Fixed formatting

http://www.daniweb.com/forums/announcement8-3.html
So when you post code, it looks like this.

int main()
{
    int x, n=0;

And not like this.
int main()
{
int x, n=0;

> is there any way to make it shorter?
Of course there is, but that's not necessarily a good measure of "success" for a program. Doing the right thing, and being easy for the average programmer to comprehend without too much effort are good qualities to strive for IMO.
Coming up with some crazy one-liner might take me an hour, and you a few days to comprehend what's going on, but it still won't teach you anything.

> #include <iostream.h>
> #include <conio.h>
These are obsolete header files.

If your C++ compiler won't accept

#include <iostream>
using namespace std;

then you need to update to something more modern.

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