C++随机数小程序
#include <iostream>
#include <time.h>
#include <windows.h>
#include <tchar.h>
using namespace std;
//打印界面
void love() {
float x, y;
for (y = 1.5f; y > -1.5f; y -= 0.1f)
{
for (x = -1.5f; x < 1.5f; x += 0.05f)
{
float a = x * x + y * y - 1;
if ((a*a*a - x * x*y*y*y) <= 0)//心形方程
cout << '*';
else cout << " ";
}
cout << endl;
}
}
int main() {
love();
cout << endl;
int MaxNumber = 0;
cout << "请输入最大数:";
cin >> MaxNumber;
cout << "最大数为->" << MaxNumber << endl;
unsigned rspeed;
srand(time(NULL));
int rnumber = rand() % MaxNumber+ 1; //因为是从0开始的所以要+1
printf("随机数结果:%d", rnumber);
getchar();
return 0;
}
效果图