/*
Program to print following pattern-
1
01
101
0101
10101
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("\n Enter the value of n:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(j=1;j<i;j++)
{
if((i+j)%2==0)
{
printf("\t 0");
}
else
{
printf("\t 1");
}
}
printf("\n");
}
getch();
}
Output:
Previous Next
Program to print following pattern-
1
01
101
0101
10101
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
printf("\n Enter the value of n:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(j=1;j<i;j++)
{
if((i+j)%2==0)
{
printf("\t 0");
}
else
{
printf("\t 1");
}
}
printf("\n");
}
getch();
}
Output:
Previous Next
There's a correction in the printf statement of if part it must print "1" and in else part printf must print "0".
ReplyDeletedepends whether you start j with 0 or 1
DeleteWhat is the use of n?
ReplyDeleteThe number of lines need to display. if you give the value of n=4. n-1 line will be displayed
Delete1
01
101
Your j for loop is wrong
ReplyDelete