Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 25-12-2007, 02:27 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: Nov 2007
Posts: 16
Default Anyone help me to solve problems


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??????????
manubatham20 is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 25-12-2007, 06:02 PM   #2 (permalink)
damn busy...
 
utsav's Avatar
 
Join Date: Sep 2006
Location: Jhansi/Meerut
Posts: 1,991
Default Re: Anyone help me to solve problems

School homework ryt?
__________________
MSI GX660 with ATI 5870 :grin: ultimate gaming lappy :grin:
Dell Studio 15(1555)
1TB+1.5TB external|N86|ZTE Blade|5230|E63|EP-630|Soundmagic PL50|Sennheiser CXL 400|Meelec M11P+
www.techjunkiez.com
utsav is offline  
Old 25-12-2007, 08:56 PM   #3 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Anyone help me to solve problems

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
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 03-01-2008, 03:49 AM   #4 (permalink)
Fresh Stock Since 2005
 
Join Date: Feb 2005
Posts: 1,015
Default Re: Anyone help me to solve problems

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!
__________________
http://www.khattam.info
khattam_ is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Solve this in c++ perk_bud Programming 5 25-11-2007 08:23 PM
solve this !! frogonfloor Programming 3 20-11-2007 08:36 AM
Plz solve these three ?ns Siddharth Maheshwari QnA (read only) 23 24-01-2007 08:24 PM
Solve this... SystemError Software Q&A 2 11-03-2006 06:45 PM
Help Please Solve my Problems ramu QnA (read only) 18 23-02-2005 03:21 PM

 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:46 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2