Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Write a Program to print as follows: (http://www.go4expert.com/forums/write-program-print-follows-t632/)

meghna 14Mar2006 10:43

Write a Program to print as follows:
 
Write a Program to print as follows:
*
* # *
* # $ # *
* # $ + $ # *
* # $ # *
* # *
*

coderzone 14Mar2006 12:19

Re: Write a Program to print as follows:
 
Simple. Here it is

Code: C

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.


All times are GMT +5.5. The time now is 13:56.