C 程序创建SIN COS和切线值

  • 本文关键字:COS 程序 创建 SIN c++
  • 更新时间 :
  • 英文 :


我是C 语言的新手,并且正在尝试创建一个程序,该程序将输出罪恶,cos和切线的所有值。假设该表在使用for循环时以10的速度以10的速度进行0至360。我一直在循环中遇到非停止错误,并想知道是否有人可以告诉我我在做什么错。任何和所有建议都将受到赞赏。

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double x, r;
double sin(x), cos(x), tan(x);
double PI = 3.1415926;
for (x = 0:10:360)
 r= x * PI /180.0;
 cout << "The sin of:" << x << "is:" <<sin(r) << "n" << endl;
 cout << "The cos of:" << x << "is:" <<cos(r) << "n" << endl;
 cout << "The tan of:" << x << "is:" <<sin(r)/cos(r) << "n" << endl;
 return 0;

}

您的 for循环语法是错误的,您缺少一些括号 - 尝试:

for (x = 0.0; x < 360.0; x += 10.0)
{
    r = x * PI / 180.0;
    cout << "The sin of: " << x << " is: " << sin(r) << endl;
    cout << "The cos of: " << x << " is: " << cos(r) << endl;
    cout << "The tan of: " << x << " is: " << tan(r) << endl;
}

最新更新