Problem statement:- Program to find the sum of series 1+4+9+16+25+.....+N
Data requirement:-
Input Data:- n
Output Data:- a, b
Additional Data:- i, k, p
Program in C
Here is the source code of the C Program to find the sum of series 1+4+9+16+25+.....+N.
Code:
#include<stdio.h>
#include<math.h>
int main()
{
int n,sum=0,i;
printf("Enter the range of number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum+=pow(i,2);
}
printf("The sum of the series = %d",sum);
}
#include<math.h>
int main()
{
int n,sum=0,i;
printf("Enter the range of number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum+=pow(i,2);
}
printf("The sum of the series = %d",sum);
}
Enter the range of number:5
The sum of the series = 55
Program in C++
Here is the source code of the C++ Program to find the sum of series 1+4+9+16+25+.....+N.
The sum of the series = 55
Program in C++
Here is the source code of the C++ Program to find the sum of series 1+4+9+16+25+.....+N.
Code:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,sum=0,i;
cout<<"Enter the range of number:";
cin>>n;
for(i=1;i<=n;i++)
{
sum+=pow(i,2);
}
cout<<"The sum of the series = "<<sum;
}
#include<cmath>
using namespace std;
int main()
{
int n,sum=0,i;
cout<<"Enter the range of number:";
cin>>n;
for(i=1;i<=n;i++)
{
sum+=pow(i,2);
}
cout<<"The sum of the series = "<<sum;
}
Input/Output:
Enter the range of number:12
The sum of the series = 650
Program in Java
Here is the source code of the Java Program to find the sum of series 1+4+9+16+25+.....+N.
The sum of the series = 650
Program in Java
Here is the source code of the Java Program to find the sum of series 1+4+9+16+25+.....+N.
Code:
import java.util.Scanner;
public class p31 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int n,sum=0,i;
System.out.println("Enter the range of number:");
n=cs.nextInt();
for(i=1;i<=n;i++)
{
sum+=Math.pow(i,2);
}
System.out.println("The sum of the series = "+sum);
cs.close();
}
}
public class p31 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int n,sum=0,i;
System.out.println("Enter the range of number:");
n=cs.nextInt();
for(i=1;i<=n;i++)
{
sum+=Math.pow(i,2);
}
System.out.println("The sum of the series = "+sum);
cs.close();
}
}
Input/Output:
Enter the range of number:
15
The sum of the series = 1240
Program in Python
15
The sum of the series = 1240
Here is the source code of the Python Program to find the sum of series 1+4+9 +16 +25+ .....+N.
Code:
import math
print("Enter the range of number(Limit):")
n=int(input())
i=1
while(i<=n):
sum += pow(i, 2)
i+=1
print("The sum of the series = ",sum)
print("Enter the range of number(Limit):")
n=int(input())
i=1
while(i<=n):
sum += pow(i, 2)
i+=1
print("The sum of the series = ",sum)
Enter the range of number(Limit):
31
The sum of the series = 10416.0
31
The sum of the series = 10416.0
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box