閱讀82 返回首頁    go 阿裏雲 go 技術社區[雲棲]


C/C++繪製餘弦曲線

#include <iostream>
#include <cmath>
using namespace std;
#define COL 62  //共有63列
int main()
{
double y;//縱坐標
int x;   //橫坐標
int associatedX;//由y坐標計算出對應的X坐標
int i;

for (y = 1; y >= -1; y -= 0.1) //餘弦值[-1:1]
{
associatedX = acos(y) * 10; //由y算出坐標X,並放大10倍
for (x = 0; x < associatedX; x++)
cout << " "; //在打印*之前,先把*前的空格打印
cout <<"*";      //打印左側的*

for (; x < COL-associatedX; x++)
cout << " ";  //打印從左側的*開始到右側*之前的空格
cout << "*";
           
cout << endl;     //在同一行上打印兩個*之後換到下一行
}
}

最後更新:2017-04-02 18:30:40

  上一篇:go Android創建和刪除桌麵快捷方式
  下一篇:go Android中shape的使用