C++ Program in Visual Studio with comment please,So i can follow im trying to wo
ID: 3562135 • Letter: C
Question
C++ Program in Visual Studio with comment please,So i can follow im trying to work on the Euler Projects.
The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 ? 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
unsigned long n,i,sum=0,sum1=0,d;
cout<<"Enter any number"; // enter the n, for your case n=100
cin>>n;
for(i=1;i<=n;i++)
{
d=i*i;
sum=sum+d; // sum=sum of squares=1^2+2^2+....n^2
sum1=sum1+i; // sum of numbers=1+2+...n
}
sum1=sum1*sum1; // square of sum
cout<<endl<<"Difference between sum of squares and square of sum= "<<sum-sum1;
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.