摘要:
有没有同学经常碰到一些趣味作业?这篇文章就将对“用c或者c++语言编写出月亮的东升西落,阴晴圆缺”这个作业进行细致讲解。
代码:
首先直接先奉上代码
#include <bits/stdc++.h>
using namespace std;
int a[50], b[50];
int k = 1;
void moon()
{
double x, y;
for (x = 1; x > -1; x -= 0.05)
{
for (y = 1; y > -1; y -= 0.025)
{
if ((x * x + y * y) < 1)
a[k]++;
else
b[k]++;
}
k++;
}
return;
}
int main()
{
moon();
// ANSI escape code for yellow text
string yellow = "\033[33m";
// ANSI escape code to reset text color
string reset = "\033[0m";
int ciy = 400;
int cix = 1600;
for (int f = 1; f <= 8; f++)
{
for (int q = 0; q < ciy ; q+=50)
{
for (int y1 = 1; y1 <= ciy - q; y1++)
cout << endl;
for (int i = 1; i <= k; i++)
{
for (int x1 = 1; x1 <= cix - q*2; x1++)
cout << " ";
for (int j = 1; j <= b[i] / 2; j++)
cout << " ";
for (int j = 1; j <= a[i] * f / 8; j++)
cout << yellow << "*" << reset;
cout << endl;
}
system("cls");
}
for (int q = 0; q <= ciy; q += 50)
{
for (int y1 = ciy - q; y1 <= c