c语言随机输出十个数范围在10-99之间
时间: 2024-02-13 22:02:05 浏览: 14
可以使用C语言中的rand()函数生成随机数,再通过取模和加法运算得到10-99之间的随机数。以下是示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int i;
srand(time(NULL)); // 初始化随机数种子
for (i = 0; i < 10; i++) {
int num = rand() % 90 + 10; // 生成10-99之间的随机数
printf("%d ", num);
}
return 0;
}
```
注意:为了避免每次运行程序生成的随机数相同,需要在程序开始时用当前时间来初始化随机数种子。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)