整數亂數
Q:產生0~9之間的整數亂數
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
int main(int argc, char *argv[])
{
srand(time(NULL));
cout << 0 + rand() % (9 - 0 + 1) << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
int main(int argc, char *argv[])
{
srand(time(NULL));
cout << 0 + rand() % (9 - 0 + 1) << endl;
system("PAUSE");
return EXIT_SUCCESS;
}