//Program to display:
1
1 0
1 0 1
1 0 1 0
1 0 1 0 1
#include<stdio.h>
void main()
{
clrscr();
int i,j,n,k=0,t=1;
printf("Enter any number:");
scanf("%d",&n);
for( i=1; i<=n ; i++)
{
for(j=1 ; j<=i ; j++)
{
if(j%2 != 0)
printf("%d", t);
else
printf("%d", k);
}
printf("\n");
}
getch();
}
Output:
Enter any number:5
1
1 0
1 0 1
1 0 1 0
1 0 1 0 1
1
1 0
1 0 1
1 0 1 0
1 0 1 0 1
#include<stdio.h>
void main()
{
clrscr();
int i,j,n,k=0,t=1;
printf("Enter any number:");
scanf("%d",&n);
for( i=1; i<=n ; i++)
{
for(j=1 ; j<=i ; j++)
{
if(j%2 != 0)
printf("%d", t);
else
printf("%d", k);
}
printf("\n");
}
getch();
}
Output:
Enter any number:5
1
1 0
1 0 1
1 0 1 0
1 0 1 0 1
No comments:
Post a Comment