Saturday, 29 October 2011

C program to print pattern

WRITE A C PROGRAM TO PRINT THE FOLLOWING PATTERN:
1
01
101






#include<stdio.h>
#include<conio.h>
void main()
{
 int i,j,n,x,s;
 printf("Enter the number of rows:");
 scanf("%d",&n);
 printf("The pettern is:\n")
 for(i=1;i<=n;i++)
 {
  x=i;
  for(j=1;j<=i;j++)
  {
   x%2==0?s=0:s=1;
   printf("%d",s);
   x++;
  }
  printf("\n");
 }
 getch();
}




Output:
   Enter the number of  rows:3
   The pettern is:
   1
   01
   101

No comments:

Post a Comment