65,210
社区成员
发帖
与我相关
我的任务
分享
#include "iostream"
#include "cmath"
using namespace std;
const float Pi = 3.14159265358979323846f;
const int Width = 40;
const int Step = 5;
int main()
{
for (int i = Step; i >= -Step; i -= 1)
{
int a = 0;
int b = 0;
if (i >= 0)
{
a = (int)(asinf(i / (float)Step) / (2.f * Pi) * Width);
b = Width / 2 - a;
}
else
{
a = -(int)(asinf(i / (float)Step) / (2.f * Pi) * Width) + Width / 2;
b = Width - (a - Width / 2);
}
for (int j = 0; j < Width; ++j)
{
if (j == a || j == b)
cout<<"*";
else
cout<<" ";
}
cout<<endl;
}
return 0;
}
-------------
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
#include <math.h>
#include <iostream>
#include <iomanip>
using namespace std;
#define PI 3.1415926f
int line = 0;
char a[20][20] = {' '};
int main()
{
for(float x = 0.0; x < 2 * PI; x += PI / 10.0f)
{
a[line][int(sin(x) * 10) + 10] = '*';
line ++ ;
}
for (int i = 0; i< 20;i++)
{
for (int j = 0; j< 20;j++)
{
cout << a[j][i];
}
cout << endl;
}
return 0;
}
#include <math.h>
#include <iostream>
#include <iomanip>
using namespace std;
#define PI 3.1415926f
int main()
{
for(float x = 0.0; x < 2 * PI; x += PI / 10.0f)
{
cout << std::setw(int(sin(x) * 10) + 10) << '*' << endl;
}
return 0;
}