![]() |
| | #1 |
| Registered User Join Date: Sep 2008
Posts: 7
| Well i wanted a output of a prorgram to look like this, i tried but can't figured out the logic, can anyone plesae help me out here with this 1 232 34543 4567654 567898765 |
| internet_bug is offline | |
| | #2 |
| and the Hat of Ass Join Date: Dec 2007
Posts: 731
| Effort required. |
| rags_to_riches is online now | |
| | #3 |
| Registered User Join Date: Sep 2008
Posts: 7
| yes mate i tried from my side, but needed some expert here |
| internet_bug is offline | |
| | #4 |
| Its hard... But im here Join Date: Apr 2005 Location: England
Posts: 1,466
| One way to tackle it is to think about the shape first. You know its a triangle so its going to need for loops, more than likely nested loops. Within each increment of the inner loop calculate/print the number. If you are having trouble, think about the pescudo code first, or plan it out on paper.
__________________ I'm just trying to be a better person - My Name Is Earl |
| swgh is offline | |
| | #5 |
| Registered User Join Date: Sep 2008
Posts: 7
| thankz for your suggesetion M8, i have figured it out that there will be nested looping in this, but can't get to the logic of looping |
| internet_bug is offline | |
| | #6 |
| Registered User Join Date: Sep 2008
Posts: 21
| These types of things are interesting. Look at this table: (0 represents space or padding) 000010000 000232000 003454300 045676540 567898765 What do we need to know. We need to know how much padding or space to provide, how many true digits to print, and what those digits should be. 1. The "row" is going to go from 1 to 5; 2. The "pad" is going to go from 4 to 0; 3. The maximum value in the row is equal to the total number of digits printed. Look at this table: row|pad|max 1 4 1 2 3 3 3 2 5 4 1 7 5 0 9 What can we learn: 1. pad = 5 - row; 2. max = (2 * row) -1; Here is how to do it, step by step. Code: /* Outer loop */
for(row = 1; row <= 5; ++ row){
/* The pad loop. notice that as row increments the number of spaces printed decrements */
for(pad = row; pad < 5; ++ pad)
printf(" ");
/* Now we are going to print the digits. This requires two loops. One that increments to "max", and one decrements back to "row */
max = (2 * row) -1;
for(col = row; col <= max; ++ col)
printf("%d",col);
for(col = max - 1; col >= row; -- col)
printf("%d",col);
/* Finish with a newline */
printf("\n");
}
|
| rmetcalf is offline | |
| | #7 |
| Banned Join Date: Aug 2001 Location: Visalia, CA, USA
Posts: 3,699
| Ok... well think of the math involved a little more. Think about the fact that the first number is going to be centered and the space on each side is going to be equal (which isn't necessarily as relavant in this project since you only need to write spaces before your data, not the spaces afterward. |
| master5001 is offline | |
| | #8 | |
| Registered User Join Date: Sep 2008
Posts: 7
| Quote:
| |
| internet_bug is offline | |
| | #9 | |
| Registered User Join Date: Sep 2008
Posts: 7
| Quote:
| |
| internet_bug is offline | |
![]() |
| Tags |
| output |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| output display in screen required | imagetvr | C++ Programming | 9 | 08-19-2008 09:55 PM |
| More digits in output, particular digits output, output in *.txt | Ene Dene | C++ Programming | 4 | 11-30-2005 04:44 PM |
| help with output | s_ny33 | C Programming | 20 | 09-19-2005 11:51 PM |
| Formatting output into even columns? | Uncle Rico | C Programming | 2 | 08-16-2005 05:10 PM |
| Output problems with structures | Gkitty | C Programming | 1 | 12-16-2002 05:27 AM |