Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Pls Help..!!! Urgent!

Hello! Any master programmers there on Turbo C?
I need help on making a program about the pascal triangle T_T...
The program must display the numeral coefficient of the terms of the condition. The user will input the exponent for the condition and the coefficients will be displayed.
This should be the output:
------------------------------------------------------
(x+y)^ 3 (for example the user inputs the number 3 )

1
1 1
1 2 1
1 3 3 1
------------------------------------------------------
I need this tomorrow night! Waaaaaa!
I really need this to pass this semester....
Please! send the codes or program to [email protected]
I'll really appreciate it!! Thx!

Comments

  • stoberstober Member Posts: 9,765 ✭✭✭
    : ------------------------------------------------------
    : I need this tomorrow night! Waaaaaa!

    Can't help you if you don't post your code to show that you have made at least the minimal amount of effort to solve this yourself.
  • RavenEclipseRavenEclipse Member Posts: 4
    This program only displays the pascal triangle and i can't figure out how to manipulate it so that the user could input the exponent and it would turned out right because every time I manipulate it it always comes out wrong...T_T
    -------------------------------------------------------------
    #include
    main()
    {
    int i,j,k;
    int spaces=23;
    int basis[14];
    for(i=1; i<=13; i++)
    {
    basis[i] = 1;
    }
    printf(" Pascal triangle %6d
    ", basis[13]);
    printf(" %6d%5d
    ", basis[12], basis[13]);
    for(i=12; i>=2; i--)
    {
    for(j=i; j<=12; j++)
    {
    basis[j] += basis[j+1];
    }
    spaces -= 2;
    printf("%*s", spaces, " ");
    for(k=i-1; k<=13; k++)
    {
    printf("%5d", basis[k]);
    }
    printf("
    ");
    }
    return 0;
    }

  • stoberstober Member Posts: 9,765 ✭✭✭
    [b][red]This message was edited by stober at 2005-8-20 10:40:3[/red][/b][hr]
    I think you need to replace the numbers 12 and 13 with a variable -- exponent and (exponent+1). If that gives you the correct results, then all you need to add is prompt and input code to get the exponent from keyboard instead of hardcoding it.
    [code]
    main()
    {
    int i,j,k;
    int spaces=23;
    int basis[14];
    [red] int exponent = 3; [/red]
    for(i=1; i<=13; i++)
    {
    basis[i] = 1;
    }
    printf(" Pascal triangle %6d
    ", basis[13]);
    printf(" %6d%5d
    ", basis[12], basis[13]);
    for(i=12; i>=2; i--)
    {
    for(j=i; j<=[red]exponent[/red]; j++)
    {
    basis[j] += basis[j+1];
    }
    spaces -= 2;
    printf("%*s", spaces, " ");
    for(k=i-1; k<= [red](exponent+1)[/red]; k++)
    {
    printf("%5d", basis[k]);
    }
    printf("
    ");
    }
    return 0;
    }

    [/code]


  • DonotaloDonotalo Member Posts: 715
    see what happens when the values of the [red]red marked[/red] constants are changed:

    : #include
    : main()
    : {
    : int i,j,k;
    : int spaces=23;
    : int basis[[blue]14[/blue]];
    : for(i=[blue]1[/blue]; i<=[blue]13[/blue]; i++)
    : {
    : basis[i] = 1;
    : }
    : printf(" Pascal triangle %6d
    ", basis[13]);
    : printf(" %6d%5d
    ", basis[12], basis[13]);
    : for(i=[red]12[/red]; i>=2; i--)
    : {
    : for(j=i; j<=[red]12[/red]; j++)
    : {
    : basis[j] += basis[j+1];
    : }
    : spaces -= 2;
    : printf("%*s", spaces, " ");
    : for(k=i-1; k<=[red]13[/red]; k++)
    : {
    : printf("%5d", basis[k]);
    : }
    : printf("
    ");
    : }
    : return 0;
    : }

    also think about [blue]blue marked[/blue] constants.
  • RavenEclipseRavenEclipse Member Posts: 4
    W0w! Thanks stober!!! Ur a genius!!
Sign In or Register to comment.