1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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:
    734
    Likes Received:
    37
    Trophy Points:
    0
    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