The Big Billion Days is Back On Flipkart


Latest
Check re Check the recent posts below

Follow by Email

Thursday, 27 June 2013

Q. Write a C program to generate pascal triangle or Write a C program to print following number triangle :







1






1
1




1
2
1


1
3
3
1
1
4
6
4
1

Solution:

#include<stdio.h>
#include<conio.h>

void main()
{
    int a,b,i,j,d[30],t[30];
    clrscr();
    printf("Enter the max limit:");
        scanf("%d",&a);
    b=a;
    for(i=0;i< a;i++)
    {

//Initialisation..
        t[0]=1; t[i]=1;
d[0]=1;

//Spacing..
        for(j=0;j< b-1;j++)
            printf(" ");
        b--;

//Calculation..
        for(j=1;j<=i;j++)
        {
        d[j]=t[j-1]+t[j];
        }
        d[i]=1;

//Printing..
        for(j=0;j<=i;j++)
        {
            printf("%d ",d[j]);
            t[j]=d[j]; //Restoring temporary Array..
        }

        printf("\n");
    }
getch();
}


Sample Output:





Note: 
 " Hi I am a Learner of C/C++. I have done this program with my own Knowledge. There may be an easy way to solve this program. So I am sorry if this program in your point of view is too long. "


No comments:

Post a Comment

Hello Friends...! Lets share Your Views,Ideas,Comments here....!!

Follow by Email

Popular Posts

Created by FOREVER FRIENDS