diamond problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanjay123456
    New Member
    • Sep 2006
    • 125

    diamond problem

    dear friends

    how can we solve diamond problem by scope reslution operator ?

    sanjay
  • RADAR
    New Member
    • Oct 2006
    • 21

    #2
    I can do it with using for structure.
    Code:
    #include<stdio.h>
    int main()
    {
    int a,z,i,j,n,x,y=1,k=1,m;
    printf("Enter height it must be odd");
    scanf("%d",&a);
    x=a;
    z=x;
    m=x;
    m--;
    m=m/2;
    m++;
    for(j=0;j<m;j++)
    	{
    for(i=0;i<x;i++)
    	printf(" ");
    if(k==1)
    {printf("*\n\n");
    x--;
    k++;
    continue;}
    	printf("*");
    	n=y;
    	for(;0<y;y--)
    	printf(" ");
    	printf("*");
    	printf("\n");
    n=n+2;	
    y=n;
    x--;
    k++;
    printf("\n");
    }
    m=m-2;
    x=x+2;
    y=y-4;
    for(j=0;j<m;j++)
    {
    for(i=0;i<x;i++)
    	printf(" ");
    	printf("*");
    	n=y;
    	for(;0<y;y--)
    	printf(" ");
    	printf("*");
    	printf("\n");
    n=n-2;
    x++;
    y=n;
    printf("\n");
    }
    for(i=0;i<z;i++)
    printf(" ");
    printf("*\n");
    return 0;
    }
    it may be quite confusing don't just look at the variables but search for what you need to do.If you can ask the question understandably I will try to answer your question

    Comment

    Working...