| | |
Triangle made with numbers from 1 to 9
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 9
Reputation:
Solved Threads: 0
Hi!
I have to write program, who print Triangle made with numbers from 1 to 9,like this:
1
21
321
4321
54321
654321
7654321
87654321
987654321
I wrote code:
which put on the screen Triangle in form:
1
12
123
1234
12345
123456
1234567
12345678
123456789
I think, that I need to use if statment to invert numbers, but i dont know how. Any ideas?
I have to write program, who print Triangle made with numbers from 1 to 9,like this:
1
21
321
4321
54321
654321
7654321
87654321
987654321
I wrote code:
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <stdlib.h> int main() { int first, last; cout << endl; for (first = 1 ; first <= 9 ; first++) { cout << " "; for (last = 1 ; last <= first; last++) { cout <<last; } cout<< endl; } cout << endl << endl << endl; system("PAUSE"); return 0; }
which put on the screen Triangle in form:
1
12
123
1234
12345
123456
1234567
12345678
123456789
I think, that I need to use if statment to invert numbers, but i dont know how. Any ideas?
•
•
Join Date: Jun 2006
Posts: 147
Reputation:
Solved Threads: 20
Simple replace
with
replace the above line and every thing is fine.
cpp Syntax (Toggle Plain Text)
for (last = 1 ; last <= first; last++)
cpp Syntax (Toggle Plain Text)
for (last = first ; last >=1; --last)
replace the above line and every thing is fine.
![]() |
Similar Threads
- Problem with switch statement (C++)
- please help in my graduation project (Computer Science)
- Need really real time (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: Reading the first character of a line
- Next Thread: what is the execution sequence of this code?
Views: 347 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





