[C++] 必背模板(更新中)

  • 生成0~9的随机数
#include 
#include 
using namespace std;
int main() {
    srand(unsigned(time(0)));
    int number = rand() % 10;
    return 0;
}
  • 生成1~10的随机数
#include 
#include 
using namespace std;
int main() {
    srand(unsigned(time(0)));
    int number = rand() % 10 + 1;
    return 0;
}

 

你可能感兴趣的:(C/C++)