#include<iostream>
#include<cmath> // pow、sqrt
#include<cstdlib> // rand、srand
#include<ctime> // time
using namespace std;
int main()
{
double a=3.5,b,d;
int c,e;
b=pow(a,3);
c=int(b);
d=sqrt(b);
cout<<b<<endl;
cout<<c<<endl;
cout<<d<<endl;
//rand函数的作用是产生随机数,但每次都是相同
//srand函数的作用是初始化随机数发生器,就是让rand函数每次产生的随机数都不相同
//rand()%(b-a+1)+a,这个公式是产生[a,b]之间的随机数
srand((unsigned)time(NULL));
e=rand()%(10-1+1)+1;//产生[1,10]之间的随机整数
cout<<e<<endl;
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: