Advertisement

OUTPUT (If line no=4) 1 0 1 1 0 1 0 1 0 1(1st line =1 digit, 2nd line = 2 digit.....)

#include<conio.h>
#include<stdio.h>
void main()
{
    clrscr();
    int i,j,k,n;
    printf("Enter line  number:");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {if(i%2!=0)
    {for(j=1;j<=i;j++)
    { if(j%2==0)
    { printf(" 0");}
    else
    {printf(" 1");}}}
     else if(i%2==0)
     {for(j=1;j<=i;j++)
    { if(j%2==0)
    { printf(" 1");}
    else
    {printf(" 0");}}}
    printf("\n");}
    getch();
                      }

No comments:

Post a Comment

Please comment bellow. Share your knowledge