{"id":25922,"date":"2017-10-25T21:23:56","date_gmt":"2017-10-25T15:53:56","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=25922"},"modified":"2017-10-25T21:23:56","modified_gmt":"2017-10-25T15:53:56","slug":"c-programming-efficient-program-calculate-ex","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/c-programming-efficient-program-calculate-ex\/","title":{"rendered":"C Programming-Efficient program to calculate e^x"},"content":{"rendered":"<p>The value of Exponential Function e^x can be expressed using following Taylor Series.<\/p>\n<p>e^x = 1 + x\/1! + x^2\/2! + x^3\/3! + \u2026\u2026<\/p>\n<p>How to efficiently calculate the sum of above series?<br \/>\nThe series can be re-written as<\/p>\n<p>e^x = 1 + (x\/1) (1 + (x\/2) (1 + (x\/3) (\u2026\u2026..) ) )<br \/>\nLet the sum needs to be calculated for n terms, we can calculate sum using following loop.<\/p>\n<p>for (i = n \u2013 1, sum = 1; i > 0; \u2013i )<br \/>\nsum = 1 + x * sum \/ i;<br \/>\nFollowing is implementation of the above idea.<\/p>\n[pastacode lang=\u201dc\u201d manual=\u201d%2F%2F%20Efficient%20program%20to%20calculate%20e%20raise%20to%20the%20power%20x%0A%23include%20%3Cstdio.h%3E%0A%20%0A%2F%2FReturns%20approximate%20value%20of%20e%5Ex%20using%20sum%20of%20first%20n%20terms%20of%20Taylor%20Series%0Afloat%20exponential(int%20n%2C%20float%20x)%0A%7B%0A%20%20%20%20float%20sum%20%3D%201.0f%3B%20%2F%2F%20initialize%20sum%20of%20series%0A%20%0A%20%20%20%20for%20(int%20i%20%3D%20n%20-%201%3B%20i%20%3E%200%3B%20\u2013i%20)%0A%20%20%20%20%20%20%20%20sum%20%3D%201%20%2B%20x%20*%20sum%20%2F%20i%3B%0A%20%0A%20%20%20%20return%20sum%3B%0A%7D%0A%20%0A%2F%2F%20Driver%20program%20to%20test%20above%20function%0Aint%20main()%0A%7B%0A%20%20%20%20int%20n%20%3D%2010%3B%0A%20%20%20%20float%20x%20%3D%201.0f%3B%0A%20%20%20%20printf(%22e%5Ex%20%3D%20%25f%22%2C%20exponential(n%2C%20x))%3B%0A%20%20%20%20return%200%3B%0A%7D\u201d message=\u201dC Program\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p>Output:<\/p>\n<pre>e^x = 2.718282<\/pre>\n[ad type=\u201dbanner\u201d]\n","protected":false},"excerpt":{"rendered":"<p>C Programming Efficient program to calculate e^x &#8211; Mathematical Algorithms &#8211; The value of Exponential Function e^x can be expressed using Taylor Series. <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69866,1,74058],"tags":[76145,76166,76143,76157,73060,75065,76137,76131,76163,76160,76161,76164,74982,76139,74184,70849,76136,76151,76146,76150,76158,76154,76148,76156,76144,76142,76152,76159,76135,76138,76155,76141,76129],"class_list":["post-25922","post","type-post","status-publish","format-standard","hentry","category-c-programming","category-coding","category-mathematical-algorithms","tag-how-to-program-in-python","tag-how-to-program-python","tag-how-to-write-a-program-in-python","tag-how-to-write-program-in-python","tag-list-count-python","tag-loop-programming","tag-math-for-programmers","tag-math-programs","tag-programming-math","tag-python-for-loop","tag-python-for-loop-list","tag-python-how-to-program","tag-python-loop-example","tag-python-programming-exercises","tag-python-repeat","tag-simple-c-programs-for-beginners","tag-software-design-process","tag-vb-net-notes","tag-vb-programs-with-coding-and-output","tag-visual-basic-6-0-notes-pdf","tag-visual-basic-controls","tag-visual-basic-form","tag-visual-basic-notes","tag-visual-basic-notes-pdf","tag-visual-basic-programming","tag-visual-basic-programs-with-codes-and-output","tag-visual-basic-theory-notes","tag-visual-basic-theory-notes-pdf","tag-visual-programming-notes","tag-what-is-python-used-for-in-programming","tag-what-is-visual-basic-used-for","tag-while-loop-in-python","tag-who-invented-c-language"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/25922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=25922"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/25922\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=25922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=25922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=25922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}