Wednesday 27 February 2013

C Program for Floyd's Triangle of 0 and 1


/*
Floyd's Triangle
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
*/
void main()
{
int i,j,k,count=1,value=1,ft;
clrscr();
for(i=1;i<10;i++)
{
ft=value;
for(j=i;j<=count;j++)
{
for(k=i;k<i+count;k++)
{
printf("%d ",value);
if(value==1)
value=0;
else value=1;
}
}
printf("\n");
count++;
if(ft==1)
value=0;
else
value=1;
}
getch();
}

No comments:

Post a Comment