Home > System Tutorial > LINUX > body text

Sum of AP series

PHPz
Release: 2024-03-13 09:43:10
forward
560 people have browsed it

A series with same common difference is known as arithmetic series. The first term of series is 'a' and common difference is d. The series looks like a, a d, a 2d, a 3d, . . . Find the sum of series.A series with the same common difference is called an arithmetic series. The first term in the series is "a" and the common difference is d. The series looks like a d, a 2d, a 3d... Find the sum of the series.

<strong>Input :</strong> a = 1
        d = 2
        n = 4
<strong>Output :</strong> 16
+ 3 + 5 + 7 = 16

<strong>Input :</strong> a = 2.5
        d = 1.5
        n = 20
<strong>Output :</strong> 335
Copy after login

Input:
The first line consists of an integer T i.e number of test cases. The first line and only line of each test case consists of three integers a,d,n.

enter:
The first line consists of the integer T, which is the number of test cases. The first and first lines of each test case consist of three integers a, d, n.

Output:
Print the sum of the series. With two decimal places.

Output:
Print the sum of the series. There are two decimal places.

Constraints:

1 1

constraint:
1 1
Example:

Input:
1 2 4
2.5 1.5 20

<strong>Output:</strong>
16.00
335.00
Copy after login

In fact, it is a summation problem of an arithmetic sequence, but it should be noted that the output is two decimal places.

The following is my code implementation:

#include 
#include 

int main()
{
    int n,i,j;
    scanf("%d",&n);
    for(i=0;i<n float a scanf printf return>
<p>Then an error occurred? Let’s take a look: </p>
<p><img src="https://img.php.cn/upload/article/000/000/164/171029420168387.png" alt="Sum of AP series">I tried the double type several times, but the same error occurred. Don’t quite understand how to do it? Where is the inspection point for this question? </p></n>
Copy after login

The above is the detailed content of Sum of AP series. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!