Sum of AP series——AP系列之和
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?”,共同的區別是d。該系列看起來像a + d,a + 2d,a + 3d。。。找到系列的總和。
Input : a = 1d = 2n = 4 Output : 16 1 + 3 + 5 + 7 = 16Input : a = 2.5d = 1.5n = 20 Output : 335Input:
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.
輸入:
第一行由整數T即測試用例數組成。每個測試用例的第一行和第一行由三個整數a,d,n組成。
Output:
Print the sum of the series. With two decimal places.
輸出:
打印系列的總和。有兩位小數。
Constraints:?
1<=T<=100
1<=a,d,n<=1000
約束:?
1 <= T <= 100?
1 <= a,d,n <= 1000
Example:
Input: 2 1 2 4 2.5 1.5 20Output: 16.00 335.00其實,就是一個等差數列的求和問題,不過需要注意的是輸出是兩位小數。
下面是我的代碼實現:
#include <stdio.h> #include <stdlib.h>int main() {int n,i,j;scanf("%d",&n);for(i=0;i<n;i++){float a,d,n;scanf("%f %f %f",&a,&d,&n);printf("%.2f\n",n*a+n*(n-1)*d/2);}return 0; }然后竟然出現了錯誤?一起來看一下:
我試了幾次的double類型,也都是這個錯誤。不是很理解怎么做?這個題目的考察點在哪里哦?
?
轉載于:https://www.cnblogs.com/wongyi/p/7672440.html
總結
以上是生活随笔為你收集整理的Sum of AP series——AP系列之和的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQLite学习(八) - SQLite
- 下一篇: bzoj1612 Usaco08 Jan