
{"id":16031,"date":"2014-11-03T09:25:15","date_gmt":"2014-11-03T09:25:15","guid":{"rendered":"http:\/\/www.beautifulwork.org\/?p=16031"},"modified":"2014-11-03T09:25:15","modified_gmt":"2014-11-03T09:25:15","slug":"how-to-write-a-program-to-solve-project-euler-problem-6","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2014\/11\/03\/how-to-write-a-program-to-solve-project-euler-problem-6\/","title":{"rendered":"How to write a program to solve project euler problem 6 ?"},"content":{"rendered":"<pre>\n\/*\n* Project Name: Problem Six\n* Solution Name: Problem Six\n* Original creation date: 06\/07\/2011\n* Edit date: 18\/01\/2013\n* Programmer name: Jamie Taylor (aka \"GaProgMan\")\n* File name: ProblemSix.c\n*\n* Purpose of this project:\n* Problem Six, from Project Euler.\n* URL: http:\/\/projecteuler.net\/index.php?section=problems&amp;id=6\n* The sum of the squares of the first ten natural numbers is,\n* 1^2 + 2^2 + ... + 10^2 = 385\n* The square of the sum of the first ten natural numbers is,\n* (1 + 2 + ... + 10)^2 = 55^2 = 3025\n* Hence the difference between the sum of the squares of the first\n* ten natural numbers and the square of the sum is 3025 - 385 = 2640.\n* Find the difference between the sum of the squares of the first\n* one hundred natural numbers and the square of the sum.\n*\n* GNU Copyright information\n* Copyright 2011 Jamie Taylor &lt;jamie@taylorj.org.uk&gt;\n*\n* This program is free software; you can redistribute\n* it and\/or modify it under the terms of the GNU General\n* Public License as published by the Free Software\n*Foundation; either version 2 of the License, or (at\n*your option) any later version.\n*\n*This program is distributed in the hope that it will\n*be useful, but WITHOUT ANY WARRANTY; without even the\n*implied warranty of MERCHANTABILITY or FITNESS FOR A\n*PARTICULAR PURPOSE. See the GNU General Public\n*License for more details.\n*\n*You should have received a copy of the GNU General\n*Public License along with this program; if not, write\n*to the Free Software Foundation, Inc., 51 Franklin\n*Street, Fifth Floor, Boston, MA 02110-1301, USA.\n*\/\n\n#include &lt;iostream&gt;\n#include &lt;math.h&gt;\n\nusing namespace std;\n\nint main () {\nunsigned long long sumOfSquares = 0;\nunsigned long long squareOfSums = 0;\nlong long difference = 0;\nint i = 1;\ndo {\nsumOfSquares += pow((double)i, 2);\nsquareOfSums += i;\ni++;\n} while ( i &lt; 101 );\n\nsquareOfSums = pow ((double)squareOfSums, 2);\ndifference = squareOfSums - sumOfSquares;\n\ncout &lt;&lt; \"Sum of all squares: \" &lt;&lt; sumOfSquares &lt;&lt; endl;\ncout &lt;&lt; \"Square of all sums: \" &lt;&lt; squareOfSums &lt;&lt; endl;\n\ncout &lt;&lt; \"The difference between the sum of all squares and the square \"\n&lt;&lt; \"of all sums is:\\n\" &lt;&lt; difference &lt;&lt; endl;\nchar ch;\n\/* cin &gt;&gt; ch; *\/\nreturn 0;\n}\n\n\/* Small changes to this file by &lt;ahiliation@yahoo.co.in&gt; Jeffrin Jose T. *\/\n\/* The pow() function returns the value of x raised to the power of y. *\/\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/* * Project Name: Problem Six * Solution Name: Problem Six * Original creation date: 06\/07\/2011 * Edit date: 18\/01\/2013 * Programmer name: Jamie Taylor (aka &#8220;GaProgMan&#8221;) * File name: ProblemSix.c * * Purpose of this project: * Problem Six, from Project Euler. * URL: http:\/\/projecteuler.net\/index.php?section=problems&amp;id=6 * The sum of the squares of the first &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2014\/11\/03\/how-to-write-a-program-to-solve-project-euler-problem-6\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to write a program to solve project euler problem 6 ?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[1516],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/16031"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=16031"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/16031\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=16031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=16031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=16031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}