#include
#include
#include
using namespace std;
int main()
{
int i=10;
double x,pi=3.14159;
while(i<=180)
{
x=i/180*pi;
cout<<"角度:"<<setw(3)<<i<<" ";
cout<<"正弦:"<<sin(x)<<" ";
cout<<"余弦:"<<cos(x)<<" "
<<endl;
i+=10;
}
return 0;
}哪里出错了
写个循环,按照格式输出即可
//以下是我的代码,看看...
#if 1
#include
#include
#include
using namespace std;
int main()
{
int i = 10;
double x, pi = 3.14159;
while (i <= 180)
{
//你出错的地方!!!
x = i * pi / 180;
cout << "角度:" << setw(3) << i << " ";
cout << "正弦:" << setiosflags(ios::fixed) << setprecision(6) << sin(x) << " ";
cout << "余弦:" << setiosflags(ios::fixed) << setprecision(6) << cos(x) << " "
<< endl;
i += 10;
}
return 0;
}
#endif
出错解释:x = i * pi / 180;这条语句你之前是这样写的: x = i / 180 * pi ;按你的来说,i/180在C语言c++语法(也许在所有编程语言中)编译器
是对其进行了取整操作。所以假如i为10,那么除以180值是几??? 肯定是0呀... 那么0在乘以pi还是零呀,而之后你的sin值就出问题了...