DIGIT-ARC read-only archive · snapshot: July 23, 2026

Anyone help me to solve problems

4 posts · originally from https://geek.digit.in/community/threads/anyone-help-me-to-solve-problems.76588/

M
manubatham20 Original post #1
Dec 25, 2007 at 2:27 PM
I am not getting the funda of the following problems-
1. Pascal triangle
2. Sin(x) series, where x is in radian sin x = x-(x^3/3!)+(x^5/5!)-(x^7/7!)+...


I tried the above programs many times but no result. Can anyone provide me its solutions??????????
utsav
utsav #2
Dec 25, 2007 at 6:02 PM
School homework ryt?
QwertyManiac
Dec 25, 2007 at 8:56 PM
Pascal's Triangle is easy if you know Combinations.

Each element is simply: P(n,k) = (n!)/(k!*(n-k)!)

Where n is the number of rows and k is 0 -> n (position value)

A simple python implementation would be like:
Code:
>>> for n in range(5): #0 to 4 = 5 rows
...     for k in range(n+1): # 0 to n = n elements
...             print fact(n)/(fact(k)*fact(n-k)),
...     print
... 
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
>>>

About the sine one, you need two counters. One odd incrementing and another for (-1)^n indication (Sign change).

In python again:
Code:
>>> def sin(x,n): # x is value, n is the iteration amount, for precision?
...     ans=0.0
...     odd=1.0
...     for p in range(n):
...             ans+=((-1)**p)*((x**odd)/fact(odd)) #(-1)^n * (x^num/num!) and on and on and on, as your series goes.
...             odd+=2.0 #increment odd number counter
...     return ans
... 
>>> sin(5,7)
-0.93758404902067816
K
khattam_ #4
Jan 3, 2008 at 3:49 AM
sin(x) series is not too difficult also...

Just sum with a loop... For alternate -ves try pow(-1,n+1)....

Thats very easy.

Do ur homework urself, or u'll not learn!