Problem statement:- Program to Find the sum of series 5^2+10^2+15^2+.....N^2.
Example:
Input: n=15
Output: The sum of the series = 350 /* sum series = 5^2+10^2+15^2=25+100+225=350*/
Input: n=20
Output: The sum of the series = 750 /* sum series = 5^2+10^2+15^2+20^2=25+100+225+=750*/
Data requirement:-
Input Data:- n
Output Data:-sum
Additional Data:- i
Program in C
Here is the source code of the C Program to find the sum of series 5^2+10^2+15^2+.....N^2.
Code:
#include<stdio.h>
#include<math.h>
int main()
{
int n,i,sum=0;
printf("Enter the range of number:");
scanf("%d",&n);
for(i=5;i<=n;i++)
{
sum+=pow(i,2);
}
printf("The sum of the series = %d",sum);
}
#include<math.h>
int main()
{
int n,i,sum=0;
printf("Enter the range of number:");
scanf("%d",&n);
for(i=5;i<=n;i++)
{
sum+=pow(i,2);
}
printf("The sum of the series = %d",sum);
}
Input/Output:
Enter the range of number:
15
The sum of the series = 350
15
The sum of the series = 350
Program in C++
Here is the source code of the C++ Program to find the sum of series 5^2+10^2+15^2+..... N^2.
Code:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i,sum=0;
cout<<"Enter the range of number:";
cin>>n;
for(i=5;i<=n;i++)
{
sum+=pow(i,2);
}
cout<<"The sum of the series = "<<sum;
}
#include<cmath>
using namespace std;
int main()
{
int n,i,sum=0;
cout<<"Enter the range of number:";
cin>>n;
for(i=5;i<=n;i++)
{
sum+=pow(i,2);
}
cout<<"The sum of the series = "<<sum;
}
Input/Output:
Enter the range of number:
20
The sum of the series = 750
20
The sum of the series = 750
Program in Java
Here is the source code of the Java Program to find the sum of series 5^2+10^2+15^2+..... N^2.
Code:
import java.util.Scanner;
public class p23 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int n,i,sum=0;
System.out.println("Enter the range of number:");
n=cs.nextInt();
for(i=5;i<=n;i+=5)
{
sum+=Math.pow(i,2);
}
System.out.println("The sum of the series = "+sum);
cs.close();
}
}
public class p23 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int n,i,sum=0;
System.out.println("Enter the range of number:");
n=cs.nextInt();
for(i=5;i<=n;i+=5)
{
sum+=Math.pow(i,2);
}
System.out.println("The sum of the series = "+sum);
cs.close();
}
}
Input/Output:
Enter the range of number:
33
The sum of the series = 2275
33
The sum of the series = 2275
Program in Python
Here is the source code of the Python Program to find the sum of series 5^2+10^2+15^2+ .....N^2.
Code:
import math
print("Enter the range of number(Limit):")
n=int(input())
i=5
sum=0
while(i<=n):
sum+=pow(i,2)
i+=5
print("The sum of the series = ",sum)
print("Enter the range of number(Limit):")
n=int(input())
i=5
sum=0
while(i<=n):
sum+=pow(i,2)
i+=5
print("The sum of the series = ",sum)
Enter the range of number(Limit):
47
The sum of the series = 7125
47
The sum of the series = 7125
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box