Home > Back-end >  C a random number
C a random number

Time:10-03

Want to calculate the number of occurrences of 1, but the output is turned into 1, change the if condition is greater than or less than is all right, is the assignment? Don't know much about
!

# include
# include
using namespace std;
Int main () {int a=0;
Srand (time (0));
for(int i=0; i<900; I++) {
Int n=rand () % 101;
If (n=1)
+;
coutcoutreturn 0; }

CodePudding user response:

Write an equal sign, less
if (n=1)
Change
 if (n==1) 

CodePudding user response:

 

# include
# include
using namespace std;
Int main ()
{
Int a=0;
Int n=0;
Srand (time (0));
for(int i=0; i<900; I++)
{
Int n=rand () % 101;
If (n==1)
+;
cout}
coutreturn 0;
}

CodePudding user response:

Want to use the==, c is this is not good, easy to make mistakes,
  • Related