1
12
123
1234
12345
1234
123
12
1
or
1
12
123
1234
12345
123456
1234567
123456789
can some1 found me some example so i can have some idea..
1
12
123
1234
12345
1234
123
12
1
or
1
12
123
1234
12345
123456
1234567
123456789
can some1 found me some example so i can have some idea..
Last edited by Aznmask; 11-13-2002 at 06:20 PM.
I did the first example using two for loops. However it come out
123454321 and not
1
2
3
4
5
4
3
2
1 but you can just format that.
IM just not exactly sure how to get 1Code:#include <iostream> #include <conio.h> // for getch using namespace std; int main () { int i; for (i = 1; i<= 5; i++) // loop to get 12345 { cout <<i; } for (i = 4; i>=1; i--) // loop to get 4321 { cout <<i; } getch(); //ignore this for my compiler return 0; }
12
123
But this is a start i guess
Aznmask,
Run a search on creating triangles. Your question is nearly as common as the "clear the screen" question.
-Skipper
"When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow
Here a small example using printf:
Code:#include <string.h> int main(void) { int i; char msg[] = "12345"; int l = strlen(msg); for(i = 1; i < l; i++) printf("%.*s\n", i, msg); for(i = l; i > 0; i--) printf("%.*s\n", i, msg); return 0; }
hmm.. i know how to get the first half of the first problem
i know there is a way to write the entire problem 1 in nested loops.. i just did it not but a week ago.. but it seems to have fled my brain.. bummer...Code:for (a = 2; a < 7; a++) { for (x = 1; x < a; x++) { cout << x; } cout << endl; }
this set of code produces the following output
Code:1 12 123 1234 12345
Originally posted by Monster
Here a small example using printf:
Code:#include <string.h> int main(void) { int i; char msg[] = "12345"; int l = strlen(msg); for(i = 1; i < l; i++) printf("%.*s\n", i, msg); for(i = l; i > 0; i--) printf("%.*s\n", i, msg); return 0; }
THANK-YOU for everyone's reply...
Hey Monster my teacher never teach us printf. Is there other command that is equal to printf? I think printf is Java's command but we learning C++
Last edited by Aznmask; 11-11-2002 at 01:09 PM.
printf() is valid in C as well as C++. (here is no cout in C.) Check out sprintf() too.
PLEASE HELP I'm not asking your guys to do my work. BUt atleast give me some hint some instruction to do those while loops
thz
Originally posted by Aznmask
PLEASE HELP I'm not asking your guys to do my work. BUt atleast give me some hint some instruction to do those while loops
thz
Here is an example of the while
while (statement) // if this is true perform statement_1 if false skip it
{
statement_1;
}
i hope this helped
cj
"Be formless, shapeless, like water... You put water into a cup, it becomes the cup, you put water into a bottle, it becomes the bottle, you put it in a teapot, it becomes the teapot... Now water can flow, or it can crash, be water my friend."
-Bruce Lee