+ 2
why displays a bunch of errors under the condition of two incidents? почему выводит кучу ошибок при условии двух случаиностей?
#include <iostream> #include <cstdlib> using namespace std; int main () { int d = srand (); int c = srand (); if (d < c) { cout << c << d; } }
1 Odpowiedź
+ 17
//Try this 👇
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main () {
srand(time(0));
int d = rand();
int c = rand();
if (d < c) {
cout << c << "\n" << d;
}
}
/*
The srand() function sets the starting point for producing a series of pseudo-random integers
Standard practice is to use the result of a call to srand(time(0)) as the seed.
rand() function is used in C++ to generate random numbers
Without srand() the same sequence of random will be generated ...
https://www-geeksforgeeks-org.cdn.ampproject.org/v/s/www.geeksforgeeks.org/rand-and-srand-in-ccpp/amp/?amp_js_v=a2&_gsa=1&usqp=mq331AQCCAE%3D#referrer=https%3A%2F%2Fwww.google.com&_tf=From%20%251%24s&share=https%3A%2F%2Fwww.geeksforgeeks.org%2Frand-and-srand-in-ccpp%2F
*/