I'm trying to create a triangle:
*
**
***
****
*****
But I can't make it.
Any help? Thanks.
I'm trying to create a triangle:
*
**
***
****
*****
But I can't make it.
Any help? Thanks.
What have you tried so far - you should know how it works by now: You post the code, we tell you how to move forward.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Use a for loop for to print each line. Inside the for loop add loop that runs to the current position in the outer loop printing a star each iteration. That would be one way of doing it.
How many stars do you need to print on each line? Think about that for a second.
Think a bit, how the value of i going from 0 to 4 could help you determine how the maximum value of j, could go from 1 to 5 and you have your answer.Code:int i, j; for(i = 0; i < 5; i++) { for(j = 0; j < 5; j++) { printf("*"); } printf("\n");
A typical example of ...cheap programming practices.Code:... goto johny_walker_red_label; johny_walker_blue_label: exit(-149$); johny_walker_red_label : exit( -22$);
Yeah, I've read it and didn't actually understand ^^
MacGyver, I'm trying to think, but failing - How to increment one star at a time? :\
I could write 5 If's but that would be a waste - I'm trying to be efficient
Yay, thanks guysCode:int i,j; for(i = 0; i < 6; i++) { for(j = 0; j < i; j++) printf("*"); printf("\n"); }
Last edited by eXeCuTeR; 02-18-2008 at 02:58 PM.
A triangle is simply a set of 3 line segments that join up together, at the core definition anyway. One can be represented in other ways as well such as using a series of figures. Let's try a filled right triangle with the right angle at the bottom left corner, the easiest kind to make. Take a few coins or something and design something that looks like this. Hint: form the right angle first then do the hypotenuse. Look for any patterns then replicate this in a program. It should be very easy as it just involves variable manipulation and 2 characters being printed, one seen, the other a line feed.
High elevation is the best elevation. The higher, the better the view!
My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express