Radical Developers welcomes all the visitors to be a member of the team. Come join us. Its all about open-source concept. All Programs are written and tested in MacOS X, Unix, Linux and may not match with the outputs of Turbo C++ in Windows

Sunday, January 9, 2011

Write a program to print the following series :

/*

0
1 0
0 1 0
1 0 1 0
*/

Source Code :

#include<stdio.h>
void main()
{
      int n,i,j=1,p;
      clrscr();
      printf("\nEnter Range : ");
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
            for(j=1;j<=i;j++)
            {
                  if((i%2==0 && j%2==0)||(i%2!=0 && j%2!=0))
                        p=0;
                  else if(i%2==0 && j%2!=0)
                        p=1;
                  else
                        p=1;
                  printf("%d ",p);
            }
            printf("\n");
      }
      getch();
}

Output :

Enter Range : 5
0
1 0
0 1 0
1 0 1 0
0 1 0 1 0

No comments:

Post a Comment