Code Competitions

Coding competition

Sunday, 12 May 2013

Program to make pascal triangle

#include<stdio.h>
#include<conio.h>
void main()
{
    int i,j,a[10][10],n;
    clrscr();
    printf("enter the number of rows");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        for(j=0;j<=i;j++)
        {
            if((j==0)||(j==i))
            {
                a[i][j]=1;
            }
            else
            {
                a[i][j]=a[i-1][j-1]+a[i-1][j];
            }
            printf("%d\t",a[i][j]);
        }
        printf("\n");
    }

    getch();
}

No comments:

Post a Comment