Diamond Asterisk

to print diamonds frm astrieks using C

Page 1 of 1

11 Replies - 51344 Views - Last Post: 12 January 2011 - 02:03 PM Rate Topic: -----

#1 dante_inverse   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-September 09

Diamond Asterisk

Posted 18 September 2009 - 11:10 PM

Iam Using this code but i need adjustments

/*to print astriek diamond*/
#include<stdio.h>
#include<conio.h>
void main()
{
  int i,j,t,max;
  clrscr();
  printf("a diamond structure in star\n\n");
  printf("what is the maximum number of columns\n\n ");
  scanf("%d", &max);

/*forward*/

  for(i=1;i<=max;i+=2)
	{
	  printf("\t");printf("\t");printf("\t");printf("\t");
	  printf("*");

	for(t=1;t<=i;t+=2)
	  {
		printf("\b");
	  }

	for(j=1;j<=i;j++)
		  { 
			printf("* ");
		  }

	  printf("\n");
	}
/*reverse*/
for(i=max-2;i>=1;i-=2)
{ 
  printf("\t");printf("\t");printf("\t");printf("\t");
  for(t=0;t<=i;t+=2)
	{
	  printf("\b");
	}
  for(j=i;j>=1;j--)
	  { 
	printf(" * ");

	  }
  printf("\n");
  max=max-1;
 }
/*scanf("%d",&dum);*/
getch();
} 



The output should be

____*
__*_*_*
*_*_*_*_*
__*_*_*
____*


without _

Is This A Good Question/Topic? 0
  • +

Replies To: Diamond Asterisk

#2 aries0152   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 13-September 09

Re: Diamond Asterisk

Posted 19 September 2009 - 02:21 AM

View Postdante_inverse, on 18 Sep, 2009 - 10:10 PM, said:

Iam Using this code but i need adjustments


Try this one-
#include <iostream>
#include<cstdlib>
#include<conio.h>
int main()
{ 
int i=0, j=0, NUM=3;



for(i=-NUM; i<=NUM; i++)
{
for(j=-NUM; j<=NUM; j++)

{

if( abs(i)+abs(j)<= NUM){ cout<<"*"; }

else { cout<<" ";}
}
cout<<endl;

}
getch();
	return 0;
}


This post has been edited by aries0152: 19 September 2009 - 02:24 AM

Was This Post Helpful? 0
  • +
  • -

#3 dante_inverse   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-September 09

Re: Diamond Asterisk

Posted 19 September 2009 - 06:05 AM

the code u have given is for c++

and i need to make it in C
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: Diamond Asterisk

Posted 19 September 2009 - 06:10 AM

Just search the forum. This question is asked EVERY. FREAKING. SEMESTER.
Was This Post Helpful? 1
  • +
  • -

#5 poncho4all   User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,422
  • Joined: 15-July 09

Re: Diamond Asterisk

Posted 19 September 2009 - 06:26 AM

Maybe this
#include <cstdio>
#include <conio.h>


int main()
	{
	int i, j, k, rows;
	printf("Specify the number of rows (between 1-19) in the dimond: ");
	scanf ("%d",&rows);
	printf("\n");
	for(i=1; i<=rows; i++)
		{
		for(j=1; j<=rows-i; j++)
		printf("%c",' ');
		for(k=1; k<=2*i-1; k++)
		printf("%c",'*');
		printf("\n");
		}
		int l,m,n;
		for (n = rows-1; n > 0;n--)
		{
		for (l = 1; l <= rows- n; l++)
		printf("%c",' ');
		for (m = 1; m<= 2 * n- 1; m++)
		printf("%c",'*');
		printf("\n");
		}
			getch();
	   }


Was This Post Helpful? 1
  • +
  • -

#6 dante_inverse   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-September 09

Re: Diamond Asterisk

Posted 19 September 2009 - 06:44 AM

man done after all...

thnk u

^_^
Was This Post Helpful? 0
  • +
  • -

#7 dante_inverse   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-September 09

Re: Diamond Asterisk

Posted 19 September 2009 - 08:16 PM

View PostJackOfAllTrades, on 19 Sep, 2009 - 05:10 AM, said:

Just search the forum. This question is asked EVERY. FREAKING. SEMESTER.


If this Qn is so Frequently asked then plz pin one of the Topic...
In students section or somewhere else... :rolleyes:
Was This Post Helpful? 0
  • +
  • -

#8 eker676   User is offline

  • Software Engineer
  • member icon

Reputation: 379
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Diamond Asterisk

Posted 19 September 2009 - 08:54 PM

There is no need to pin it. If people want the answers they can look for them. No need to spoonfeed them their homework.

This post has been edited by eker676: 19 September 2009 - 08:54 PM

Was This Post Helpful? 0
  • +
  • -

#9 carltech   User is offline

  • What did you call me?
  • member icon

Reputation: 28
  • View blog
  • Posts: 997
  • Joined: 19-October 07

Re: Diamond Asterisk

Posted 19 September 2009 - 09:44 PM

It is a good way to teach about nested loops though

loop spaces down
loop * up
loop spaces up
loop * down
Was This Post Helpful? 0
  • +
  • -

#10 poncho4all   User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,422
  • Joined: 15-July 09

Re: Diamond Asterisk

Posted 20 September 2009 - 05:33 AM

Well i agree with eker, imagine how many topics would have to be pined, besides if its a homework you could easily atleast search for it, there is im sure there is atleast one here at D.I.C, if not im sure there is at least 100000 in Google xD
Was This Post Helpful? 0
  • +
  • -

#11 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1433
  • View blog
  • Posts: 11,006
  • Joined: 06-February 08

Re: Diamond Asterisk

Posted 20 September 2009 - 05:38 AM

Added to the FAQ :)
Was This Post Helpful? 0
  • +
  • -

#12 Guest_Siddharth Bidasaria*


Reputation:

Re: Diamond Asterisk

Posted 12 January 2011 - 02:03 PM

well i have another one... just replace the value assigned with the "max". Hope it helps. Though its a little late
#include <stdio.h>  
int main(){  
    int i=10;
	int j=0;
	int k=10;
	int z=0;
	int q=0;
	int a,b,c,d;
	for (i=10; i>0; i--) 
	{
		for (j=0;j<=i;j++)
		{
			printf(" ");
		}
		z=11-i;
		q=(2*z)-2;
		for (k=0; k<=q;k++)
		{
			printf("*");
		}
		printf("\n");
	}
	for (a=1;a<=10;a++)
	{
		for(b=0;b<=a;b++)
		{
			printf(" ");
		}
		d=2*(10-a);
		for(c=0;c<=d;c++)
		{
			printf("*");
		}
		printf("\n");
	}
	return 0;
}


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

And yay, another Turbo C homework dump!

This post has been edited by JackOfAllTrades: 12 January 2011 - 02:05 PM

Was This Post Helpful? 0

Page 1 of 1