how to generate number pattern in triangular form

Posted by Vignesh Vicky on Programmers See other posts from Programmers or by Vignesh Vicky
Published on 2013-07-01T07:56:51Z Indexed on 2013/07/01 10:28 UTC
Read the original article Hit count: 242

Filed under:

I want to print this pattern like right angled triangle

0 
909 
89098 
7890987 
678909876 
56789098765 
4567890987654 
345678909876543 
23456789098765432 
1234567890987654321 

I wrote following code

# include<stdio.h>
# include<conio.h>

void main()
{   
    clrscr();
    int i,j,x,z,k,f=1;

    for ( i=10;i>=1;i--,f++)
    {

        for(j=1;j<=f;j++,k--)
    {
            k=i;
            if(k!=10)
            {
                printf("%d",k); 
            }

            if(k==10)
            {
                printf("0");
            }

        }
        for(x=1;x<f;x++,z--)
        {
            z=9;

            printf("%d",z);
        }

        printf("%d/n");

    }
    getch();
}

what is wrong with this code? when i check manually it seems correct but when compiled gives different pattern

© Programmers or respective owner

Related posts about c