Problem statement:- Program to Find the sum of series 1³+2³+3³+4³.....+N³.
Data requirement:-
Input Data:- n
Output Data:-Sum
Additional Data:- i
Program in C
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 1³+2³+3³+4³.....+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,3);
printf("The sum of the series = %d",sum);
}
Enter the range of number:5
The sum of the series = 224
Program in C++
Here is the source code of the C++ Program to Find the sum of series 1³+2³+3³+4³.....+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,3);
cout<<"The sum of the series = "<<sum;
}
Enter the range of number:8
The sum of the series = 1295
Program in Java
Here is the source code of the Java Program to Find the sum of series 1³+2³+3³+4³.....+N³.
Code:
import java.util.Scanner;
public class Sum_Of_Series10 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int n;
int sum=0,i;
System.out.println("Enter the range of number:");
n=cs.nextInt();
for(i=1;i<=n;i++)
sum+=Math.pow(i,3);
System.out.println("The sum of the series = "+sum);
cs.close();
}
}
Enter the range of number:
10
The sum of the series = 3025
Program in Python
Here is the source code of the Python Program to Find the sum of series 1³+2³+3³+4³.....+N³.
Code:
n=int(input("Enter the range of number:"))
sum=0
for i in range(1,n+1):
sum+=pow(i,3)
print("The sum of the series = ",sum)
Enter the range of number:15
The sum of the series = 14400
Most Recommend Questions:-
More Questions:-
0 Comments
Please do not Enter any spam link in the comment box