In both branches and loops, there are different statements such as the switch statement, while statement, for loop, and do-while loop. In these loops, you can add break and continue. Break is used to exit the current loop. Continue is used to skip the subsequent statements and directly enter the judgment part of the while loop or the third step of the for loop, then proceed to the judgment part and then enter the loop again.
In another part of the branches and loops, we learned the concept of generating random numbers. To generate random numbers, we need to use the rand function. The default function of rand is that the seed is unique, but it is actually a fake random number and is always the same every time. Therefore, we need to change the seed. This requires the use of the srand function. As the seed changes inside, the random numbers will also change. Just add parentheses after rand to generate a seed. If we need to change the seed in the srand at any time, we need to use the time function. The time function requires a header file. The unsigned int type conversion is used before the NULL in the time parentheses.
To generate 100 to 200 numbers randomly,we can 100+rand()%(200-100+1)
It is derived to generate a random number between a and b,
a+rand()%(b-a+1)
996

被折叠的 条评论
为什么被折叠?



