Home > Backend Development > C++ > Translate the following into Chinese: C programming to sum the first n terms of the sequence 0.6, 0.06, 0.006, 0.0006,...

Translate the following into Chinese: C programming to sum the first n terms of the sequence 0.6, 0.06, 0.006, 0.0006,...

WBOY
Release: 2023-09-01 09:17:06
forward
665 people have browsed it

Translate the following into Chinese: C programming to sum the first n terms of the sequence 0.6, 0.06, 0.006, 0.0006,...

The given series 0.6,0 .o6,.... is a geometric series where each element is the previous element divided by 10. Therefore, to find the sum of the series, we must apply the GP one formula for r whose sum is less than 1 (in our case r=0.1).

Sum = 6/10 [1- (1/10)n/(1-1/10)]
Sum = 6/9 [1- (1/10)n]
Sum = 2/3[1- (1/10n)]
Copy after login

Example

#include <stdio.h>
#include <math.h>
int main() {
   int n = 6;
   float sum = 2*((1 - 1 / pow(10, n)))/3;
   printf("sum = %f", sum);
}
Copy after login

Output

sum = 0.666666
Copy after login

The above is the detailed content of Translate the following into Chinese: C programming to sum the first n terms of the sequence 0.6, 0.06, 0.006, 0.0006,.... For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template