•
•
•
•
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
![]() |
•
•
Join Date: Dec 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
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..
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..
•
•
Join Date: Dec 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
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?
#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?
http://www.daniweb.com/forums/announcement8-3.html
So when you post code, it looks like this.
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
then you need to update to something more modern.
So when you post code, it looks like this.
c++ Syntax (Toggle Plain Text)
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;
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- dont know what kind of code this is, need help (Legacy and Other Languages)
- program depending on String class (Java)
- Some wierd kind of bug... (C++)
- Recursion Program/Code I'm having issues with... (Java)
- Can someone that knows arrays check my program out so far (C++)
- How to free up memory used for queues? (C)
- validation of some kind (C++)
- Need help writing a program to classify a poker hand (Java)
- YaBasic: The beginners choice (Computer Science and Software Design)
- How do I create a program using an Array ? (C++)
Other Threads in the C++ Forum
- Previous Thread: Help With Pascal's Triangle in C++
- Next Thread: comman line command



Linear Mode