DESCRIPTION: This program prints the triangle as below-
1
01
101
0101
10101
PROGRAM:
#include<stdio.h>
main()
{
int i,j,n,a,b;
printf("Enter the number of lines\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
if(a%2==0)
{
a=1;
b=0;
}
else
{
a=0;
b=1;
}
for(j=0;j<=i;j++)
{
if(j%2==0)
printf("%d",a);
else
printf("%d",b);
}
printf("\n");
}
}
No comments:
Post a Comment