Exforsys
+ Reply to Thread
Results 1 to 5 of 5

pascal's triangle in c

This is a discussion on pascal's triangle in c within the C and C++ forums, part of the Programming Talk category; program in c for pascal's triangle... i hav read in different books but i cant understand the logic....... is there ...

  1. #1
    ankit_golden is offline Junior Member Array
    Join Date
    Feb 2008
    Answers
    5

    Question pascal's triangle in c

    program in c for pascal's triangle...
    i hav read in different books but i cant understand the logic.......
    is there any simple logic without pointers and functions
    i want a simple program........
    can anybody help me out


  2. #2
    priyaraji is offline Member Array
    Join Date
    Apr 2006
    Answers
    52
    The program to calculate the Pascal triangle is given below:

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

    void main()
    {
    int k[10][10];
    int i,j,s,l;
    printf("How many lines?");
    scanf("&#37;d",&l);
    k[1][1]=1;
    printf("%5d",k[1][1]);
    k[2][1]=1;k[2][2]=2;k[2][3]=1;
    printf("%d %d %d",k[2][1],k[2][2],k[2][3]);
    for(i=3;i<=l;i++)
    {
    k[i][1]=1;
    printf("%d",k[i][1]);
    j=2;s=3;
    while(j<=i)
    {
    k[i][j]=k[i-1][s-1]+k[i-1][s-2];
    printf("%5d",k[i][j]);
    s=s+1;
    j=j+1;
    }
    k[i][j]=1;
    printf("%d",k[i][j]);
    }
    }

    Let me know if you are struck with any other programs in C.


  3. #3
    prakash ranjan is offline Junior Member Array
    Join Date
    Dec 2009
    Answers
    1
    sry .. this program is not working....


  4. #4
    Manyamanas is offline Member Array
    Join Date
    Dec 2010
    Answers
    32
    following code will print this pascal triangle...
    1
    1 2
    1 2 3
    1 2 3 4
    1 2 3 4 5
    till n;
    where n=limit;;;




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

    void main()
    {
    int i,j,n;
    printf("Enter the value of n\n");
    scanf("%d",&n)
    for(i=1;i<=4;i++)
    {
    for(j=1;j<=i;j++)
    {
    printf("%d",j);
    }
    printf("\n");
    }
    getch();
    }





    simple change in the for loop will generate the opposite triangle////
    54321
    4321
    321
    21
    1


    for(i=n;i>=1;i--)
    {
    for(j=1;j<=i;j++)
    {

    everything remains the same


  5. #5
    skooja is offline Junior Member Array
    Join Date
    Jan 2011
    Answers
    1
    Quote Originally Posted by Manyamanas View Post
    following code will print this pascal triangle...
    1
    1 2
    1 2 3
    1 2 3 4
    1 2 3 4 5
    till n;
    where n=limit;;;




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

    void main()
    {
    int i,j,n;
    printf("Enter the value of n\n");
    scanf("%d",&n)
    for(i=1;i<=4;i++)
    {
    for(j=1;j<=i;j++)
    {
    printf("%d",j);
    }
    printf("\n");
    }
    getch();
    }





    simple change in the for loop will generate the opposite triangle////
    54321
    4321
    321
    21
    1


    for(i=n;i>=1;i--)
    {
    for(j=1;j<=i;j++)
    {

    everything remains the same
    thx it was very simple plain program


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...