|
|
发表于 2020-10-11 11:55:44
|
显示全部楼层
本楼为最佳答案
- #include<iostream>
- #include<string>
- #include<math.h>
- #include<iomanip>
- #include<stdio.h>
- #include<ctime>
- #include<cstdlib>
- using namespace std;
- int casual()
- {
-
- int a = rand() % 6 + 1;
- //srand(2);
- int b = rand() % 6 + 1;
-
- int sum = a + b;
- cout<<a<<"+"<<b<<"="<<sum<<endl;
- return sum;
-
- }
- main()
- {
- srand(time(0)); // 把种子放在主函数里,确保只调用一次
- int any = casual();
- cout<<any<<endl;
- int any1 = casual();
- cout<<any1<<endl;
- int any2 = casual();
- cout<<any2<<endl;
- }
复制代码 |
|