{"id":35192,"date":"2016-04-06T22:13:04","date_gmt":"2016-04-07T03:13:04","guid":{"rendered":"http:\/\/diegodamy.wordpress.com\/?p=256"},"modified":"2016-04-06T22:44:23","modified_gmt":"2016-04-07T03:44:23","slug":"euler-aprox","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101winter2016\/2016\/04\/euler-aprox\/","title":{"rendered":"Euler Aprox."},"content":{"rendered":"<p>#TC1017 #QUIZ4<\/p>\n<p>So this quiz was actually kinda challenging, it took me quite some time and a lot of questions to Ken to finally work it out. All noteworthy notes can be found on the picture below.<\/p>\n<p>The factorial function was taken from one of the WSQs we did before, the tricky part was that C++ wasn\u00b4t giving me all decimals beacause of a disparity with the function&#8217;s types. Ken sorted that out&#x1f600;<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-267\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/120feab7c8e9a725e01b10ae0ca34f38.jpg\" alt=\"quiz4.PNG\"   \/><\/p>\n<p>Source Code below [GitHub Link:\u00a0https:\/\/github.com\/diegodamy\/Quiz4 ]<\/p>\n<p>#include &lt;iostream&gt;<br \/>\nusing namespace std;<\/p>\n<p>int factorial (int n){<br \/>\nif (n == 0){<br \/>\nreturn 1;<br \/>\n} else {<br \/>\nreturn n*factorial(n-1); \/\/This is an example of recursion, and must be implemented since the formula for the n factorial of any number<br \/>\n} \/\/ requires the n-1 factorial of given number<br \/>\n}<\/p>\n<p>long double euler_calc (long double prec)<br \/>\n{<br \/>\nlong double euler_sum = 0.0; \/\/It&#8217;s better to initialize this variable since we shouldn&#8217;t asssume it will start at 0 by default<br \/>\nlong double prev_sum; \/\/ Sometimes that might work but other times it could return junk memory<br \/>\nint n = 0;<\/p>\n<p>do {<\/p>\n<p>prev_sum = euler_sum;<br \/>\neuler_sum = euler_sum + 1.0\/ (factorial(n)); \/\/ The &#8220;1.0&#8221; here is VERY important, otherwise it won\u00c2\u00b4t compile correctly.<br \/>\nn = n+1; \/\/ A simple &#8220;1&#8221; won\u00c2\u00b4t work because C++ will stupidly convert our long double variable into an int one, which we don\u00c2\u00b4t want<\/p>\n<p>} while (euler_sum &#8211; prev_sum &gt; prec);<\/p>\n<p>return euler_sum;<br \/>\n}<\/p>\n<p>int main(){<\/p>\n<p>long double precision;<\/p>\n<p>cout &lt;&lt; &#8220;Please input the value of precision:&#8221; &lt;&lt; endl;<br \/>\ncin &gt;&gt; precision;<\/p>\n<p>cout &lt;&lt; &#8220;Result is: &#8221; &lt;&lt; euler_calc(precision);<br \/>\n}<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>Photo Credit: &lt;a href=&#8221;<a href=\"https:\/\/www.flickr.com\/photos\/57329804@N00\/9984539064\/&#8221;&gt;spanaut&lt;\/a&#038;%23038;gt\" rel=\"nofollow\">https:\/\/www.flickr.com\/photos\/57329804@N00\/9984539064\/&#8221;&gt;spanaut&lt;\/a&#038;gt<\/a>; via &lt;a href=&#8221;<a href=\"http:\/\/compfight.com&#038;\/#8221;&gt;Compfight&lt;\/a&#038;%23038;gt\" rel=\"nofollow\">http:\/\/compfight.com&#8221;&gt;Compfight&lt;\/a&#038;gt<\/a>; &lt;a href=&#8221;<a href=\"https:\/\/creativecommons.org\/licenses\/by-nc-sa\/2.0\/&#8221;&gt;cc&lt;\/a&#038;%23038;gt\" rel=\"nofollow\">https:\/\/creativecommons.org\/licenses\/by-nc-sa\/2.0\/&#8221;&gt;cc&lt;\/a&#038;gt<\/a>;<\/p>\n<p>  <a rel=\"nofollow\" href=\"http:\/\/feeds.wordpress.com\/1.0\/gocomments\/diegodamy.wordpress.com\/256\/\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/d7ef02cfd2d119d17b7a8f97d70ddaca.jpg\" \/><\/a> <img loading=\"lazy\" decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/04\/d9e810539e5b9981ef86a240fa5d2b22.jpg#038;blog=105336245&#038;%23038;post=256&#038;%23038;subd=diegodamy&#038;%23038;ref=&#038;%23038;feed=1\" width=\"1\" height=\"1\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>#TC1017 #QUIZ4 So this quiz was actually kinda challenging, it took me quite some time and a lot of questions to Ken to finally work it out. All noteworthy notes can be found on the picture below. The factorial function was taken from one of the WSQs we did before, the tricky part was that &hellip; <a href=\"https:\/\/kenscourses.com\/tc101winter2016\/2016\/04\/euler-aprox\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Euler Aprox.<\/span><\/a><\/p>\n","protected":false},"author":20,"featured_media":35210,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[32,200],"class_list":["post-35192","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogs","category-syndicated","tag-tc1017","tag-quiz4"],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/35192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/comments?post=35192"}],"version-history":[{"count":2,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/35192\/revisions"}],"predecessor-version":[{"id":35215,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/35192\/revisions\/35215"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/media\/35210"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/media?parent=35192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/categories?post=35192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/tags?post=35192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}