Write a Program to print as follows:

Discussion in 'C' started by meghna, Mar 14, 2006.

  1. meghna

    meghna New Member

    Joined:
    Mar 14, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Write a Program to print as follows:
    *
    * # *
    * # $ # *
    * # $ + $ # *
    * # $ # *
    * # *
    *
     
  2. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    736
    Likes Received:
    39
    Trophy Points:
    28
    Simple. Here it is

    Code:
    int row,col,sp=4,res;
    for(col=1;col<=5;col++)
    {
    	res=sp;
    	for(;sp>0;sp--)
    		printf("  ");
    	res--;
    	sp=res;
    	for(row=1;row<=col;row++)
    		printf("%d ",row);
    	for(row=col-1;row>0;row--)
    		printf("%d ",row);
    	printf("\n");
    }
    It will print as 1,2,... and you can initialize the array elements to have your own characters.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice