|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
| Sponsored Links |
|
|
|
|||||
|
Is the only input function from the user one of the height; nothing else?
__________________
Funny Stories and Humorous Pictures |
|
|||||
|
Am I missing something? The height of the diamond above appears to be 7.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
|
|||||
|
assuming you meant 7 for the input:
(7-1)/2 = 3, the number of spaces before the first/last * each row decreases/increases the lead space by 1 each row increases/decreases the inner spaces by 2 (with 1 center space inserted as well) So, your spaces are: 3 2,2+1 1,4+1 0,6+1 1,4+1 2,2+1 3 From that, you should be able to build 2 for loops to draw the diamond. Also, you need to be sure the value entered is odd.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
| Sponsored Links |
|
|
|
|||||
|
Ups, I've written the input wrong. Sorry for that.
Assuming the input 7 is right. WingedPanther thank you very much for your explanation. I'll start to writting after this post. It'll work. Thank you very very much. Code:
#include <stdio.h>
main()
{
int h, led, inner, star;
printf("please enter the height of diamond> ");
scanf("%d", &h);
for ( led = (h-1)/2 ; led<=0 ; led-- )
printf(" ");
for ( star = 1 ; star<=2 ; star++ )
printf("*");
for ( inner = 0 ; inner<=h-2 ; inner++ )
printf(" ");
for ( led = (h-1)/2 ; led <=0 ; led--) {
printf(" ");
printf("\n"); }
system("pause");
return 0;
}
Last edited by Irfanerol; 05-13-2008 at 06:49 AM. |
|
|||||
|
You need to wrap your for loops in a for loop to cycle through the rows.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| pattern recognition, template generator | bartonski | Programming Theory | 1 | 02-14-2008 07:23 AM |
| ! Need urgent help ! Drawing program using cygwin | siren | C and C++ | 0 | 05-26-2007 10:51 PM |