求级数的和?3 + ?12 +………最新条款
原文:https://www . geesforgeks . org/find-系列之和-% E2 % 88% 9 a3-% E2 % 88% 9a 12-up-n-terms/
给定一个数 n,任务是求这个级数前 n 项的和。以下是该系列:
例:
Input: n = 10
Output: 95.2628
Input: n = 5
Output: 25.9808
这个系列可以看作是-
下面是需要的实现:
C++
// C++ implementation of above approach
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
// Function to find the sum
double findSum(ll n)
{
// Apply AP formula
return sqrt(3) * (n * (n + 1) / 2);
}
// Driver code
int main()
{
// number of terms
ll n = 10;
cout << findSum(n) << endl;
return 0;
}
Java 语言(一种计算机语言,尤用于创建网站)
// Java implementation of
// above approach
import java.io.*;
class GFG
{
// Function to find the sum
static double findSum(long n)
{
// Apply AP formula
return Math.sqrt(3) * (n *
(n + 1) / 2);
}
// Driver code
public static void main (String[] args)
{
// number of terms
long n = 10;
System.out.println( findSum(n));
}
}
// This code is contributed
// by inder_verma..
Python 3
# Python3 implementation of above approach
#Function to find the sum
import math
def findSum(n):
# Apply AP formula
return math.sqrt(3) * (n * (n + 1) / 2)
# Driver code
# number of terms
if __name__=='__main__':
n = 10
print(findSum(n))
# This code is contributed by sahilshelangia
C
// C# implementation of
// above approach
using System;
class GFG
{
// Function to find the sum
static double findSum(long n)
{
// Apply AP formula
return Math.Sqrt(3) * (n *
(n + 1) / 2);
}
// Driver code
public static void Main ()
{
// number of terms
long n = 10;
Console.WriteLine( findSum(n));
}
}
// This code is contributed
// by inder_verma..
服务器端编程语言(Professional Hypertext Preprocessor 的缩写)
<?php
// PHP implementation of above approach
// Function to find the sum
function findSum($n)
{
// Apply AP formula
return sqrt(3) * ($n * ($n + 1) / 2);
}
// Driver code
// number of terms
$n = 10;
echo findSum($n);
// This code is contributed
// by inder_verma
?>
java 描述语言
<script>
// Javascript implementation of
// above approach
// Function to find the sum
function findSum( n)
{
// Apply AP formula
return Math.sqrt(3) * (n * (n + 1) / 2);
}
// Driver code
// number of terms
let n = 10;
document.write(findSum(n).toFixed(4));
// This code is contributed by 29AjayKumar
</script>
Output:
95.2628
版权属于:月萌API www.moonapi.com,转载请注明出处