User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,759 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 361 | Replies: 3
Reply
Join Date: Dec 2007
Posts: 5
Reputation: finalheavenx is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
finalheavenx finalheavenx is offline Offline
Newbie Poster

Help help me program this kind of output..

  #1  
Dec 4th, 2007
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..
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: help me program this kind of output..

  #2  
Dec 4th, 2007
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.
Reply With Quote  
Join Date: Dec 2007
Posts: 5
Reputation: finalheavenx is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
finalheavenx finalheavenx is offline Offline
Newbie Poster

Re: help me program this kind of output..

  #3  
Dec 4th, 2007
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?
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: help me program this kind of output..

  #4  
Dec 4th, 2007
http://www.daniweb.com/forums/announcement8-3.html
So when you post code, it looks like this.
  1. int main()
  2. {
  3. 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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 9:27 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC