You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.0 KiB
80 lines
1.0 KiB
/*随机输出2个数算法--Apxar*/
|
|
/*随机输出2个数算法--Apxar*/
|
|
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
#include<time.h>
|
|
int main(void)
|
|
{
|
|
|
|
int i,j,k=2,num1,num2,sum=0,answer,score=0,xiabiao,temp;
|
|
char fuhao[2]={'+','-'};
|
|
srand((int)time(0));
|
|
|
|
for(i=1;i<=10;i++)
|
|
{
|
|
|
|
xiabiao=rand()%2;
|
|
num1=rand()*50/32767;
|
|
num2=rand()*50/32767;
|
|
if(xiabiao==0)
|
|
{ sum=num1+num2;}
|
|
else
|
|
{ sum=num1-num2;}
|
|
|
|
if(sum>=0&&sum<=50)
|
|
{
|
|
j=2; k=1;
|
|
|
|
printf("\n(%d).\n",i);
|
|
printf("%7d\n",num1);
|
|
printf("%c\n",fuhao[xiabiao]);
|
|
printf("%7d\n",num2);
|
|
printf("------------\n");
|
|
printf("请输入正确答案 ");
|
|
scanf("%d",&answer);
|
|
|
|
if(sum==answer)
|
|
|
|
{
|
|
printf("\n结果:你输入的答案正确! \n\n");
|
|
score+=10;
|
|
}
|
|
|
|
else
|
|
{
|
|
while(j<=3)
|
|
{
|
|
printf("\n答案错误,请重新输入:");
|
|
scanf("%d",&answer);
|
|
if(sum==answer)
|
|
{
|
|
printf("\n结果:你输入的答案正确! \n\n");
|
|
k++;
|
|
|
|
if(k==2)
|
|
{ score+=7;}
|
|
else if(k==3)
|
|
{ score+=5;}
|
|
|
|
break;
|
|
|
|
}
|
|
else
|
|
|
|
{ k++;}
|
|
j++;
|
|
|
|
}
|
|
if(j>3)
|
|
printf("\n该题正确答案为:%d\n",sum);
|
|
|
|
}
|
|
|
|
}
|
|
else
|
|
|
|
i--;
|
|
}
|
|
printf("\n共%d道题目,你的总分为%d\n \n",i-1,score);
|
|
}
|