C++中关于三角函数的一道题

来源:百度知道 编辑:UC知道 时间:2024/09/01 18:52:50
// 三角函数.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char* argv[])
{
int a;
a=sin(1);
cout<<a<<endl;
return 0;
}
这道程序在Visusal C++6.0里运行结果总是0.不知道为什么?

呵呵,类型用错了,你用int类型的就对sin的结果取整了.正弦值都是在[-1,1]里的,除了值为1或-1的其它取整后当然都是0啊.
int a;
这个改成double就行了.

这里顺便提醒一下,数学函数的参数,返回值一般都是double型的.