一半拋物線程式碼
#include <iostream>
using namespace std;
const int X=100, Y=100;
int main(){
char screen[X][Y];
// 初始化畫布
for (int j=0; j<Y; j++)
for(int i=0; i<X; i++)
screen[i][j] = '_';
// 繪製 y = x^2 的曲線
for (int x=1; x<=30; x++)
screen[3*x][(x*x)/10] = '*';
// 輸出畫布
for (int j=Y-1; j>=0; j--){
for (int i=0; i<X; i++)
cout << screen[i][j];
cout << endl;
}
return 0;
}
輸出結果
完整拋物線程式碼
#include <iostream>
using namespace std;
const int X = 100, Y = 100;
int main(){
char screen[X][Y];
// 初始化畫布
for (int j = 0; j < Y; j++)
for(int i = 0; i < X; i++)
screen[i][j] = '_';
// 繪製 y = x^2 的曲線
for (int x = -15; x <= 15; x++){
int y = x * x;
screen[3 * (x + 15)][y / 3] = '*';
}
// 輸出畫布
for (int j = Y-1; j >= 0; j--){
for (int i = 0; i < X; i++)
cout << screen[i][j];
cout << endl;
}
return 0;
}
輸出結果