求数列的和
思路:利用sqrt函数计算根号,再依次累计相加
代码:
#include<iostream> #include<math.h> using namespace std; int main() { double m, n; double num, sum; while (cin >> m >> n) { sum = 0; num = m; int i; for (i = 0; i < n; i++) { sum += num; num = sqrt(num); } printf("%0.2lf\n", sum); } system("pause"); return 0; }
原文地址:https://www.cnblogs.com/pcdl/p/12250509.html
时间: 2024-11-10 18:36:01