㈠ 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;
}