Java program to calculate sum of series (1+2)/(1*2)+(1+2+3)/(1*2*3)+------(1+2+3+------n)/(1*2*3*4-------n)
Answers
Answered by
26
ANSWER
............
#include<stdio.h>
int main(){
int n,sum,sum1=0,i,j;
printf("Please enter an integer n=");
scanf("%d",&n);
for(i=1;i<=n;i++){
sum=0;
for(j=1;j<=i;j++)
sum=sum+j;
sum1=sum1+sum;
}
printf("The sum of the series=%d\n",sum1);
return 0;
............
#include<stdio.h>
int main(){
int n,sum,sum1=0,i,j;
printf("Please enter an integer n=");
scanf("%d",&n);
for(i=1;i<=n;i++){
sum=0;
for(j=1;j<=i;j++)
sum=sum+j;
sum1=sum1+sum;
}
printf("The sum of the series=%d\n",sum1);
return 0;
Attachments:
Answered by
1
C++
// C++ program to find the sum of given series
#include <bits/stdc++.h>
using namespace std;
// function to find the sum of given series
double sumOfTheSeries(int n)
{
// Computing sum term by term
double sum = 0.0;
for (int i = 1; i <= n; i++)
sum += 1.0 / (i * (i + 1));
return sum;
}
// driver program to test above function
int main()
{
int n = 10;
cout << sumOfTheSeries(n);
return 0;
}
java
class demo {
// function to find the sum of given series
public static double sumOfTheSeries(int n)
{
// Computing sum term by term
double sum = 0.0;
for (int i = 1; i <= n; i++)
sum += 1.0 / (i * (i + 1));
return sum;
}
// driver program to test above function
public static void main(String args[])
{
int n = 10;
System.out.println(sumOfTheSeries(n));
}
}
// C++ program to find the sum of given series
#include <bits/stdc++.h>
using namespace std;
// function to find the sum of given series
double sumOfTheSeries(int n)
{
// Computing sum term by term
double sum = 0.0;
for (int i = 1; i <= n; i++)
sum += 1.0 / (i * (i + 1));
return sum;
}
// driver program to test above function
int main()
{
int n = 10;
cout << sumOfTheSeries(n);
return 0;
}
java
class demo {
// function to find the sum of given series
public static double sumOfTheSeries(int n)
{
// Computing sum term by term
double sum = 0.0;
for (int i = 1; i <= n; i++)
sum += 1.0 / (i * (i + 1));
return sum;
}
// driver program to test above function
public static void main(String args[])
{
int n = 10;
System.out.println(sumOfTheSeries(n));
}
}
Similar questions