C program for triangle number pattern 18/0,1

C program for triangle number pattern 18/0,1

This program is to print triangle number pattern 18/0,1 in C.

1
0 0
1  1  1
0 0 0 0
1  1  1  1 1

If you need a dry run of the program or any other query, then kindly leave a comment in the comment box or mail me, I would be more than happy to help you.

Program

#include<stdio.h>
 
void main()
{
    int i,j,n;
 
    printf("Enter the no of lines\n");
    scanf("%d",&n);
 
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=i;j++)
        {
            if(i%2==1)
            {
                printf("1 ");
            }
            else
            {
                printf("0 ");
            }
        }
        printf("\n");
    }
}

Output

Share Me!