C program to print following pattern 1 01 101 0101

/*
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:


5 comments:

  1. There's a correction in the printf statement of if part it must print "1" and in else part printf must print "0".

    ReplyDelete
  2. Replies
    1. The number of lines need to display. if you give the value of n=4. n-1 line will be displayed
      1
      01
      101

      Delete

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...