void 求数列的和()
{//缘由https://bbs.csdn.net/topics/394827750
int i=0, n=0, m=0;
double x=1.0, he=0;
cout << "Windows下为组合键Ctrl+Z结束" << endl;
while (scanf_s("%d %d", &n, &m) != EOF)
{
he += x *= n;
while (m > ++i){ cout << sqrt(x)<<endl; he += x=sqrt(x); }
printf_s("%.2f\n", he);
he = 0; x = 1.0; i = n = m = 0;
}
}
void 求数列的和()
{//缘由https://bbs.csdn.net/topics/394827750
int i=0, n=0, m=0,xu=0;
double x = 1.0, he = 0, 和集合[44] = {0};
cout << "Windows下为组合键Ctrl+Z结束" << endl;
while (scanf_s("%d %d", &n, &m) != EOF)
{
he += x *= n;
while (m > ++i){ cout << sqrt(x)<<endl; he += x=sqrt(x); }
和集合[xu] = he; ++xu;
he = 0; x = 1.0; i = n = m = 0;
}
while (xu)printf_s("%.2f\n", 和集合[--xu]);
}
void 求数列的和()
{//缘由https://bbs.csdn.net/topics/394827750
int i = 0, n = 0, m = 0, xu = 0;
double x = 1.0, he = 0, 和集合[44] = { 0 };
string shuch = "";
cout << "Windows下为组合键Ctrl+Z结束" << endl;
while (scanf_s("%d %d", &n, &m) != EOF)
{
he += x *= n;
while (m > ++i){ cout << sqrt(x) << endl; he += x = sqrt(x); }
//和集合[xu++] = he;
shuch += to_string((__int64)(he*100.0+0.5)/100.0) + "\n";//100.0表示2位to_string(9).find("9")==string::npos//对比字符串包含
he = 0; x = 1; i = 0;
}
//while (xu)printf_s("%.2f\n", 和集合[--xu]);
cout << shuch << endl;
}
2种正序输出
i = xu;
while (xu)printf_s("%.2f\n", 和集合[i - xu--]);
i = 0;
while (i<xu)printf_s("%.2f\n", 和集合[i++]);