Dado el número de términos ien Hallar la suma de la serie 0.6, 0.06, 0.006, 0.0006, …a n términos.
Ejemplos:
Input : 2 Output : 0.65934 Input : 3 Output : 0.665334
Denotemos la suma por S:
Usando la fórmula , tenemos [ya que r<1]
Por lo tanto, la suma requerida es
A continuación se muestra la implementación:
C++
// CPP program to find sum of 0.6, 0.06, // 0.006, 0.0006, ...to n terms #include <bits/stdc++.h> using namespace std; // function which return the // the sum of series float sumOfSeries(int n) { return (0.666) * (1 - 1 / pow(10, n)); } // Driver code int main() { int n = 2; cout << sumOfSeries(n); }
Java
// java program to find sum of 0.6, 0.06, // 0.006, 0.0006, ...to n terms import java.io.*; class GFG { // function which return the // the sum of series static double sumOfSeries(int n) { return (0.666) * (1 - 1 /Math. pow(10, n)); } // Driver code public static void main (String[] args) { int n = 2; System.out.println ( sumOfSeries(n)); } } // This code is contributed by vt_m
Python3
# Python3 program to find # sum of 0.6, 0.06, 0.006, # 0.0006, ...to n terms import math # function which return # the sum of series def sumOfSeries(n): return ((0.666) * (1 - 1 / pow(10, n))); # Driver code n = 2; print(sumOfSeries(n)); # This code is contributed by mits
C#
// C# program to find sum of 0.6, 0.06, // 0.006, 0.0006, ...to n terms using System; class GFG { // function which return the // the sum of series static double sumOfSeries(int n) { return (0.666) * (1 - 1 /Math. Pow(10, n)); } // Driver code public static void Main () { int n = 2; Console.WriteLine( sumOfSeries(n)); } } // This code is contributed by vt_m
PHP
<?php // PHP program to find sum of 0.6, 0.06, // 0.006, 0.0006, ...to n terms // function which return the // the sum of series function sumOfSeries($n) { return (0.666) * (1 - 1 / pow(10, $n)); } // Driver code $n = 2; echo(sumOfSeries($n)); // This code is contributed by Ajit. ?>
Javascript
<script> // javascript program to find sum of 0.6, 0.06, // 0.006, 0.0006, ...to n terms // function which return the // the sum of series function sumOfSeries( n) { return (0.666) * (1 - 1 / Math.pow(10, n)); } // Driver Code let n = 2 ; document.write(sumOfSeries(n).toFixed(5)) ; // This code is contributed by aashish1995 </script>
Producción:
0.65934
Publicación traducida automáticamente
Artículo escrito por Sagar Shukla y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA