c++这个程序为什么没有输出

#include
#include
using namespace std;
const double OUT = 1e-6;
double sinx(double x);
int main() {
double r, s, k;
cout << "请输入两个数:";
cin >> r >> s;

if (r*r<=s*s) 
        k = sqrt(sinx(r) * sinx(r) + sinx(s) * sinx(s));
        
    
else 
        k = 1 / 2 * sinx(r * s);
    
cout << k << endl;
    return 0;

}

double sinx(double x) {
double val = x * x;
double e = x;
double n = 0;
int i = 1;
int f = 1;

while (fabs(e/f) >= OUT) {
    i % 4 == 1 ? n += e/f: n -= e/f;
    i += 2;
    f = f * (i - 1) * i;
    e *= val;

}
return n;

}

直接调用c++的sin函数就行,你自己写的进入死循环了:

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
const double OUT = 1e-6;

int main()
{
    double r, s, k;
    cout << "请输入两个数:";
    cin >> r >> s;
    if (r*r<=s*s)
        k = sqrt(sin(r) * sin(r) + sin(s) * sin(s));
    else
        k = 1 / 2 * sin(r * s);

    cout << k << endl;
    return 0;
}

img

可能你的运算,陷入了while死循环。

兄弟建议你改一下编码习惯