Write a c++ program to input 5 elements and to display it's square.
Answers
Answered by
1
Answer:
CPP Program to find sum of square of first n natural numbers
#include <bits/stdc++.h>
using namespace std;
// Return the sum of the square
// of first n natural numbers
int squaresum(int n)
{
// Iterate i from 1 and n
// finding square of i and add to sum.
int sum = 0;
for (int i = 1; i <= n; i++)
sum += (i * i);
return sum;
}
// Driven Program
int main()
{
int n = 4;
cout << squaresum(n) << endl;
return 0;
}
Explanation:
hope it's helpful
Similar questions
English,
3 months ago
Accountancy,
3 months ago
Math,
7 months ago
English,
10 months ago
Chemistry,
10 months ago