Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 2nd, 2007, 1:32 PM   #1
blouro
Newbie
 
Join Date: Oct 2007
Posts: 1
Rep Power: 0 blouro is on a distinguished road
diamond asterics problem

i was given 10 asterics problems to do. i've completed all of them except for this one. i've given up. i can only get half of the diagram to print

its supposed to print like this

************* row 1 0 spaces ,13*
******-****** row 2 1 spaces, 12*
*****-- -***** row 3 3 spaces, 10*
****----- **** row4 5 spaces, 8*
***------- *** row5 7 spaces ,6*
**--------- **row6 9 spaces, 4*
* ----------- *row7 11 spaces, 2*
**--------- **row8 9 spaces ,4*
***------- ***row9 7 spaces ,6*
****----- ****row10 5 spaces ,8*
*****--- *****row11 3 spaces ,10*
****** -******row12 1 spaces ,12*
*************row13 0 spaces ,13*



so far i have
for(int rows = -6; rows <=6; rows++)
{
	for(int st = 1+ abs(rows)+1; st>0; st--)
	{
		printf("*");

	}
	printf("\n");
}

but this only pritns half the *'s

if anyone can help me do the other half it will be greatly appreciated.

i can only use printf(" ") printf("*") printf("\n") once in the whole block of code.

thank you

Last edited by big_k105; Oct 2nd, 2007 at 1:54 PM. Reason: Added Code Tags
blouro is offline   Reply With Quote
Old Oct 2nd, 2007, 8:09 PM   #2
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 417
Rep Power: 4 Wizard1988 is on a distinguished road
Send a message via AIM to Wizard1988
Try to come up with a mathematical expression for when a star shoudl be printed or not using x and y variables (Row vs Column)
__________________
JG-Webdesign
Wizard1988 is offline   Reply With Quote
Old Oct 3rd, 2007, 4:39 AM   #3
avinashmalipatil
Newbie
 
Join Date: Sep 2007
Posts: 14
Rep Power: 0 avinashmalipatil is an unknown quantity at this point
Here is the code...
But remember never giveup, keep trying until u find the solution..
#include<stdio.h>

int main()
{
	int row, space=0,ast=13,count;

	for(row=0;row<13;row++)
	{
	 	for(count=1;count<=ast/2;count++)
		{
			printf("*");
		}

		if(ast==13)
		{
			printf("*");
		}
				
		for(count=1;count<=space;count++)
		{
			printf(" ");
		}
		
		for(count=1;count<=ast/2;count++)
		{
			printf("*");
		}
		
		if(row<6)
		{
			if(space==0)
			{
				space++;
				ast--;
			}
			else 
			{
				space+=2;
				ast-=2;
			}
		}
		else
		{
			if(space==1)
			{
				space--;
				ast++;
			}
			else 
			{
				space-=2;
				ast+=2;
			}
		}
	 		printf("\n");
		}
return 0;
}

Last edited by big_k105; Oct 5th, 2007 at 4:54 PM. Reason: Added Code Tags
avinashmalipatil is offline   Reply With Quote
Old Oct 3rd, 2007, 9:01 AM   #4
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
avinashmalipatil: count your printfs - look at the requirements.
The Dark is offline   Reply With Quote
Old Oct 4th, 2007, 12:40 AM   #5
avinashmalipatil
Newbie
 
Join Date: Sep 2007
Posts: 14
Rep Power: 0 avinashmalipatil is an unknown quantity at this point
Here i have modified the code. If there is any mistake, let me know.
#include<stdio.h>

int main()
{
	int row, space=-1,ast=7,col;

	for(row=1;row<=13;row++)
	{
	 	for(col=1;col<=13;col++)
		{
			if(col>ast && col<=(ast+2*space+1) && ast!=7)
			{
				printf(" ");
			}
			else
			{
				printf("*");
			}
		}
		
			if(row<7)
			{
				ast--;
				space++;
			}
			else
			{
				ast++;
				space--;
			}
		
		printf("\n");
	}
return 0;
}

Last edited by big_k105; Oct 5th, 2007 at 4:54 PM. Reason: Added Code Tags
avinashmalipatil is offline   Reply With Quote
Old Oct 4th, 2007, 6:52 PM   #6
Seif
Hobbyist Programmer
 
Seif's Avatar
 
Join Date: Jan 2006
Location: UK
Posts: 215
Rep Power: 3 Seif is on a distinguished road
code tags ftw
Seif is offline   Reply With Quote
Old Oct 4th, 2007, 7:32 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
This is not an entirely straightforward problem because of the similarities between the first and second rows and the penultimate and ultimate rows, and the requirement for a minimum of printf statements.

It will require a tad of thinking beforehand to resolve those impediments. I would recommend dividing the problem horizontally (left, center, and right portions), and then incorporate that into the vertical dimension. Use value transitions as a key to behavior modification.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 5th, 2007, 12:00 AM   #8
avinashmalipatil
Newbie
 
Join Date: Sep 2007
Posts: 14
Rep Power: 0 avinashmalipatil is an unknown quantity at this point
Quote:
Originally Posted by Seif View Post
code tags ftw
Sorry, I didnt get you. wat do u mean by "code tags ftw"?
__________________
Avinash
INDIA
avinashmalipatil is offline   Reply With Quote
Old Oct 5th, 2007, 4:17 PM   #9
peaceofpi
hi: for(;;) goto hi;
 
peaceofpi's Avatar
 
Join Date: Jun 2006
Posts: 93
Rep Power: 3 peaceofpi is on a distinguished road
Send a message via AIM to peaceofpi Send a message via MSN to peaceofpi
Quote:
Originally Posted by avinashmalipatil View Post
Sorry, I didnt get you. wat do u mean by "code tags ftw"?
He means try reading the rules and using code tags so your post isn't painful to look at.
__________________
How do you play Religious Roulette?
Stand around in a circle and blaspheme till someone gets struck by lightning.
peaceofpi is offline   Reply With Quote
Old Oct 8th, 2007, 2:17 AM   #10
avinashmalipatil
Newbie
 
Join Date: Sep 2007
Posts: 14
Rep Power: 0 avinashmalipatil is an unknown quantity at this point
The code is so small and i dont think code tags r required. U can easily understand the code, its so simple. And there is no reply from Blouro. Is ur ploblem solved?
__________________
Avinash
INDIA
avinashmalipatil is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
<td> height problem grimpirate HTML / XHTML / CSS 19 May 4th, 2007 6:01 AM
Stuck with a C problem Polaris C++ 8 Aug 19th, 2006 3:30 PM
cgi/perl script + IE problem joyceshee Perl 2 Jan 24th, 2006 11:10 AM
Variable array problem Hintshigen C 6 Apr 10th, 2005 2:35 PM
string problem when passing in linked list quantz C++ 0 Feb 27th, 2005 10:11 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:23 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC