结果没有意义

what does the result do not make sense?

本文关键字:有意义 结果      更新时间:2023-10-16

我已经编程了一个小程序以查找任何数字的cosbur结果都是奇怪的CMD:

键入数字0.00

effincisy5

您的cos = 008C129E

按任何键继续。。。

代码:

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
float cos67 (float l,float j)
{
    int k=0;
    float sum=0,i=1;
    while (k<=j)
    {
        sum +=i;
        i*=(-l*l/((2*l)*(2*l-1)));
        k+=1;
    }
    return sum;
}
int main(){
    float l,j;
    cout<<"type the number ";
    cin>>l;
    cout<<endl<<"effincisy" ;
    cin>>j;
    cout<<endl;
    cos67(l,j);
    cout<<"your cos ="<<cos67<<endl;
    return 0;
}

为什么结果在数字上有字母?

或它是什么意思?

this:

 cout<<"your cos ="<<cos67<<endl;

正在获取功能的地址并显示它。您需要函数返回的值:

 cout<<"your cos ="<< cos67(l,j) <<endl;

您正在打印函数的地址,而不是返回值。使用:

cout<<"your cos ="<< cos67(l, j) <<endl;

而不是。