Saturday 17 November 2012

Sum of Squares of Integers

//Write a program to calculate the sum of squares of integers 1 to n. where n is the value entered by user. i.e(sum=12+22+32+42+52................n2).

#include <iostream>
using namespace std;
int main()
{
int num,sum=0;
cout << "Enter The value of n: ";
cin >>num;
for (int i=1;i<=num;i++)
{
sum=sum+(i*i);
}
cout << "Sum is: " << sum <<endl;
return 0;
}

No comments:

Post a Comment