Que: Write a C program to display the following different Patterns.
1
0 1
1 0 1
0 1 0 1
Code:
#include <stdio.h>
int main(void) {
int i, j;
for (i = 0; i < 4; i++)
{
for (j = 0; j <= i; j++)
{
if (((i + j) % 2) == 0)
{
printf("1");
}
else
{
printf("0");
}
printf(" ");
}
printf("\n");
}
return 0;
}
1
0 1
1 0 1
0 1 0 1
Code:
#include <stdio.h>
int main(void) {
int i, j;
for (i = 0; i < 4; i++)
{
for (j = 0; j <= i; j++)
{
if (((i + j) % 2) == 0)
{
printf("1");
}
else
{
printf("0");
}
printf(" ");
}
printf("\n");
}
return 0;
}
Logic:
No comments:
Post a Comment