㈠ C语言如何编程产生随机数
楼主你好,给你个最简单的C程序
#include<stdio.h>
#include<stdlib.h>//这个是随机数函数rand()所在头文件,就像使用scanf要包含stdio.h。
voidmain()
{
inti=100;
while(i--)
{
printf("-------%d---",rand()%1000);
}
}
㈡ C语言如何编程产生随机数
1、首先打开Visual stdio 2019,依次点击文件,新建,项拆喊目新建以一个空白的项目:
㈢ c语言问题 请问如何随机产生加减乘除任意一种运算符号呢
#include<stdlib.h>
#include<time.h>
intmain()
{
inta,b,i,s,num,n=0;
charch,cal[4]={'+','-','*','/'};
srand(time(NULL));
for(i=0;i<10;i++)
{
a=rand()%10+1;
ch=cal[rand()%4];
b=rand()%10+1;
printf("%d%c%d=",a,ch,b);
switch(ch)
{
case'+':s=a+b;break;
case'-':s=a-b;break;
case'*':s=a*b;break;
case'/':s=a/b;break;
}
scanf("%d",&num);
if(num==s)
{
printf("Right! ");
n++;
}
elseprintf("Wrong! ");
}
printf("总分:%d 正确率:%%%d",n*10,n*10);
return0;
}