This C++ program will find the sum of squares of n natural numbers. Starting from 1, 2, 3, etc are called natural numbers.
For example:
n = 3
Then, Sum = 12 + 22 + 32 = 14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#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
Very gd I understand very good
The provided code is very useful.will you please provide the same code using do while loop
The code provided was useful in correcting the code i had written. Could you please provide the Algorithm for this program?
Thanks in advance!!
In while loop
Find the sum of square of first N natural numbers
C++ program please send this program?
Please reply
this is very useful thanks