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 :


/*
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
*/

Source Code :

#include<stdio.h>
void main()
{
      int x[5][5],i,j;
      clrscr();
      for(i=1;i<=5;i++)
      {
            for(j=1;j<=i;j++)
            {
                  if(j==1)
                        x[i][j]=1;
                  else if(i==j)
                        x[i][j]=1;
                  else
                        x[i][j]=x[i-1][j-1]+x[i-1][j];
            }
            for(j=1;j<=i;j++)
                  printf("%d ",x[i][j]);
            printf("\n");
      }
      getch();
}

Output :

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

No comments:

Post a Comment