Subscribe

RSS Feed (xml)

Thursday, January 8, 2009

Write a C program to generate Pascal’s triangle.

#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(conio.h)
int main(void)
{
int arr[10][10];
int i, j, k;
clrscr();
printf("\nProgram for printing Pascal's Triangle:\n\n\n");
for(i=0; i<10; i++)
{
j=1;
arr[i][0]=1;
arr[i][i]=1;
while( j< i) {
arr[i][j]=arr[i-1][ j-1]+arr[i-1][ j];
j++; }
}
for(i=0;i <10;i++) //display part
{
j=10;
while( j>i) { printf(" "); //mention 2 spaces betw the double quotes
j--;
}
for(k=0;k<=i;k++)

{
printf("%4d",arr[i][k]);
}
printf("\n\n");
} //display for loop close
getch();
return 0;
} //main close

4 comments:

  1. Hi Ram.this is nageswara Rao.i saw u r site.there lot of information in c language.i completed M.C.A in 2009.present doing lecture in HYD. i want more programes in C,C++ language and tutorial.
    plz send to my mail id thati.nag1986@gmail.com
    plz.
    than you sir

    ReplyDelete
  2. hi Ram m anchal.i love c programming. m quite poor in file handling and Data structure with C.plz plz provide me some tutorials or ny other type of help to cover it.plz reply me on mystery_raj2000@yahoo.co.in

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. hello sir
    i m Tanpreet kaur pursuing MCA.plz provide me some tutorials based on c language and some tips to design the logic of the problems.waiting for your reply on richerich9920@gmail.com

    ReplyDelete