Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

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.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-11-2008, 03:50 PM
Irfanerol's Avatar   
Irfanerol Irfanerol is offline
Newbie
 
Join Date: May 2008
Posts: 10
Rep Power: 0
Irfanerol is on a distinguished road
Default Drawing diamond shaped pattern with C

Hello,
I'm new in C language, nowadays I'm just solving the basic problems of C. I couldn't find a way to solve this problem. Could someone show me a way to solve this problem? I don't want C code. Only a simple guide for solving.
Thanks for help.

-- The program will get the height of diamond from keyboard and it will print a diamond
according to this height. If entered value is 9 output will be
Code:
    *    
   * *
  *   *
 *     *
  *   *
   * *
    *

Last edited by Irfanerol; 05-11-2008 at 03:55 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 05-11-2008, 04:59 PM
DevilsCharm's Avatar   
DevilsCharm DevilsCharm is offline
Programming God
 
Join Date: Jul 2006
Posts: 887
Rep Power: 13
DevilsCharm is on a distinguished road
Default Re: Drawing diamond shaped pattern with C

Is the only input function from the user one of the height; nothing else?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-11-2008, 05:46 PM
Irfanerol's Avatar   
Irfanerol Irfanerol is offline
Newbie
 
Join Date: May 2008
Posts: 10
Rep Power: 0
Irfanerol is on a distinguished road
Default Re: Drawing diamond shaped pattern with C

just height.
other lenghts of diamond will be calculated by our function
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-11-2008, 06:45 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,633
Last Blog:
Passwords
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
Send a message via AIM to John
Default Re: Drawing diamond shaped pattern with C

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-12-2008, 12:07 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,034
Last Blog:
NaNoWriMo Day 23 The...
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default Re: Drawing diamond shaped pattern with C

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 05-12-2008, 02:45 PM
Irfanerol's Avatar   
Irfanerol Irfanerol is offline
Newbie
 
Join Date: May 2008
Posts: 10
Rep Power: 0
Irfanerol is on a distinguished road
Default Re: Drawing diamond shaped pattern with C

--please del this post--

Last edited by Irfanerol; 05-12-2008 at 04:05 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-12-2008, 03:58 PM
Irfanerol's Avatar   
Irfanerol Irfanerol is offline
Newbie
 
Join Date: May 2008
Posts: 10
Rep Power: 0
Irfanerol is on a distinguished road
Default Re: Drawing diamond shaped pattern with C

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;
}
I couldn't understand what's wrong with this code? I think I did everything true?

Last edited by Irfanerol; 05-13-2008 at 06:49 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 05-13-2008, 11:54 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,034
Last Blog:
NaNoWriMo Day 23 The...
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default Re: Drawing diamond shaped pattern with C

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -5. The time now is 09:34 PM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 65%

Ads