8 Replies - 296 Views - Last Post: 05 November 2019 - 01:59 PM Rate Topic: -----

#1 peater_123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 05-November 19

Need a help with a Pascal triangle

Posted 05 November 2019 - 10:49 AM

I would like to ask for help.
I have to program Pascal triangle in C so it printout any off the lines/rows that i chose.
Here is a pic off the triangle:

https://kurzy.kpi.fe...ages/pascal.png

For example i need the numbers from the forth line from the top saved to an array with value 1,3,3,1 in this example.

Any ideas ? Bcs i have tried already few things and i've deleted them all bcs they haven't worked as expected.
Ty for help.

Is This A Good Question/Topic? 0
  • +

Replies To: Need a help with a Pascal triangle

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15361
  • View blog
  • Posts: 61,607
  • Joined: 12-June 08

Re: Need a help with a Pascal triangle

Posted 05 November 2019 - 10:58 AM

What have you tried, thought about, or considered?
Was This Post Helpful? 0
  • +
  • -

#3 peater_123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 05-November 19

Re: Need a help with a Pascal triangle

Posted 05 November 2019 - 11:03 AM

This is my last attempt that i haven't deleted yet

long sum_squared(const int line){
    int a;
   while(line>0){
   	int n = line ,k;
    k=a++;
    printf("%d,",binomialCoeff(n,k));
   }

}
int binomialCoeff(int n, int k){
  if (k==0 || k==n){
    return 1;
  }
  return  binomialCoeff(n-1, k-1) + binomialCoeff(n-1, k);
}

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15361
  • View blog
  • Posts: 61,607
  • Joined: 12-June 08

Re: Need a help with a Pascal triangle

Posted 05 November 2019 - 11:47 AM

Super. Now what isn't working so hot in that? The numbers? The spacing?
Was This Post Helpful? 0
  • +
  • -

#5 peater_123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 05-November 19

Re: Need a help with a Pascal triangle

Posted 05 November 2019 - 12:12 PM

The part of the code that i sended is working proberly.

But i need exponenciate all the numbers in the line/row and then add them up to get one result.
And that part is not working very hot thats the part that i keep deleting bcs i dont know how to implement it into my code properly.Any idea how can i do it ?

For example i need to do this but i dont know how.
1^2+4^2+6^2+4^2+1^2=1+16+36+16+1=70
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15361
  • View blog
  • Posts: 61,607
  • Joined: 12-June 08

Re: Need a help with a Pascal triangle

Posted 05 November 2019 - 01:16 PM

I think you yoinked the wrong chunk of code.

Try this link for breaking down the math.
https://www.geeksfor...ascal-triangle/
Was This Post Helpful? 0
  • +
  • -

#7 peater_123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 05-November 19

Re: Need a help with a Pascal triangle

Posted 05 November 2019 - 01:39 PM

I've already visited this site but i couldn't implement any of those things to my code or at last i dont know how to be more precise.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15361
  • View blog
  • Posts: 61,607
  • Joined: 12-June 08

Re: Need a help with a Pascal triangle

Posted 05 November 2019 - 01:41 PM

Okay what's tripping you up with their example? The looping or being not recursive?
Was This Post Helpful? 0
  • +
  • -

#9 peater_123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 05-November 19

Re: Need a help with a Pascal triangle

Posted 05 November 2019 - 01:59 PM

I dont have a problem with writing out the numbers from the line/row, i have problem working with the values from this line i need to adjust those values with help of the math operations like sum,exp aso. but i dont know how to work with them properly.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1