日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Sum of AP series——AP系列之和

發布時間:2025/3/15 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 : 335

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.

輸入:
第一行由整數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系列之和的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。