C++ Program to Find Sum of Square of n Natural Numbers

#include<iostream>
 
using namespace std;
 
int main()
{
	unsigned long n,i,sum=0,d;
	cout<<"Enter any number:";
	cin>>n;
 
	for(i=1;i<=n;++i)
	{
		d=i*i;
		sum+=d;
	}
 
	cout<<"Sum="<<sum;
	return 0;
}

Output

Enter any number: 50

Sum=42925

Leave a Comment

error: Alert: Content is protected!!