In this C program, we will learn how to write a program to print two right-angle triangles in opposite directions using a Binary Number.
Here is the code of the program to print two right-angle triangles in opposite directions using a Binary Number.
/*C Program to Print Two Right Angle Triangle in opposite Direction using a Binary Number:
0 0
01 01
010 010
0101 0101
0101001010
*/
#include<stdio.h>
int main()
{
int i,j,k,l=8,m,n,o,p;
for(i=0; i<=4; i++)
{
for(j=0; j<=i; j++)
{
if(j%2==0)
printf("0");
else
printf("1");
}
for(k=1; k<=l; k++)
{
printf(" ");
}
l = l-2;
for(m=0; m<=i; m++)
{
if(m%2==0)
printf("0");
else
printf("1");
}
printf("\n");
}
return 0;
}
0 0
01 01
010 010
0101 0101
0101001010
--------------------------------
Process exited after 0.06946 seconds with return value 0
Press any key to continue . . .
Comments