如题所述
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
int scan()
{
char s[100];
int i,t,z=0;
do
{
z=0;
gets(s);
for(i=0;s[i]!='\0';i++)
if(s[i]<'0' || s[i]>'9') break;
if(i>=strlen(s))
for(t=0;s[t]!='\0';t++)
z=z*10+((int)s[t]-48);
else
printf("æ¨çè¾å ¥æ误ï¼è¯·éæ°è¾å ¥");
}
while(i<strlen(s));
return(z);
}
int x=1,y=1,choice=0,sum=0,right=0,z=0,answer;
float precent;
char fuhao;
void suiji()
{
srand(time(NULL));
x=rand()%100+1;
y=rand()%100+1;
}
void choose()
{
int yunsuan(int,int,int);
if(sum==0) precent=0.0;
else precent=(float)right/sum;
printf("\nå¦éè¿è¡å åä¹é¤è¿ç®æµè¯ï¼è¯·åå«è¾å ¥1ã2ã3ã4\n");
printf("å¦ééåºè¯·è¾å ¥5\n");
choice=scan();
switch(choice)
{
case 1:printf("欢è¿æ¥å°å æ³è¿ç®æµè¯ç³»ç»,å¦ééåºè¯·è¾å ¥9999\n");fuhao='+';break;
case 2:printf("欢è¿æ¥å°åæ³è¿ç®æµè¯ç³»ç»,å¦ééåºè¯·è¾å ¥9999\n");fuhao='-';break;
case 3:printf("欢è¿æ¥å°ä¹æ³è¿ç®æµè¯ç³»ç»,å¦ééåºè¯·è¾å ¥9999\n");fuhao='*';break;
case 4:printf("欢è¿æ¥å°é¤æ³è¿ç®æµè¯ç³»ç»,å¦ééåºè¯·è¾å ¥9999\n");fuhao='/';break;
case 5:printf("æ¬æ¬¡æµè¯æå¿«ï¼æ¬¢è¿ä¸æ¬¡åæ¥æµè¯\n");
printf("æ¬æ¬¡å ±å%déé¢ï¼å ¶ä¸%déæ£ç¡®ï¼æ£ç¡®ç为%f\n",sum,right,precent);
break;
default:printf("æ¨çè¾å ¥æ误ï¼è¯·éæ°è¾å ¥\n");choose();
}
}
int ans(int x,int y,int choice)
{
switch(choice)
{
case 1:z=x+y;break;
case 2:z=x-y;break;
case 3:z=x*y;break;
case 4:z=x/y;break;
}
return( z);
}
void yunsuan()
{
suiji();
printf("%d%c%d=",x,fuhao,y);
z=ans(x,y,choice);
answer=scan();
if(z==answer)
{
printf("æ£ç¡®\n");
right++;sum++;
yunsuan();
}
else if(answer==9999) choose();
else
{
printf("ä¸æ£ç¡®, æ£ç¡®çæ¡ä¸º%5d\n",z);
sum++;
yunsuan();
}
}
void main()
{
printf("欢è¿æ¥å°ååè¿ç®æµè¯ç³»ç»\n");
choose();
while(choice!=5)
yunsuan();
}追é®
#include<stdlib.h>
#include<time.h>
#include<string.h>
int scan()
{
char s[100];
int i,t,z=0;
do
{
z=0;
gets(s);
for(i=0;s[i]!='\0';i++)
if(s[i]<'0' || s[i]>'9') break;
if(i>=strlen(s))
for(t=0;s[t]!='\0';t++)
z=z*10+((int)s[t]-48);
else
printf("æ¨çè¾å ¥æ误ï¼è¯·éæ°è¾å ¥");
}
while(i<strlen(s));
return(z);
}
int x=1,y=1,choice=0,sum=0,right=0,z=0,answer;
float precent;
char fuhao;
void suiji()
{
srand(time(NULL));
x=rand()%100+1;
y=rand()%100+1;
}
void choose()
{
int yunsuan(int,int,int);
if(sum==0) precent=0.0;
else precent=(float)right/sum;
printf("\nå¦éè¿è¡å åä¹é¤è¿ç®æµè¯ï¼è¯·åå«è¾å ¥1ã2ã3ã4\n");
printf("å¦ééåºè¯·è¾å ¥5\n");
choice=scan();
switch(choice)
{
case 1:printf("欢è¿æ¥å°å æ³è¿ç®æµè¯ç³»ç»,å¦ééåºè¯·è¾å ¥9999\n");fuhao='+';break;
case 2:printf("欢è¿æ¥å°åæ³è¿ç®æµè¯ç³»ç»,å¦ééåºè¯·è¾å ¥9999\n");fuhao='-';break;
case 3:printf("欢è¿æ¥å°ä¹æ³è¿ç®æµè¯ç³»ç»,å¦ééåºè¯·è¾å ¥9999\n");fuhao='*';break;
case 4:printf("欢è¿æ¥å°é¤æ³è¿ç®æµè¯ç³»ç»,å¦ééåºè¯·è¾å ¥9999\n");fuhao='/';break;
case 5:printf("æ¬æ¬¡æµè¯æå¿«ï¼æ¬¢è¿ä¸æ¬¡åæ¥æµè¯\n");
printf("æ¬æ¬¡å ±å%déé¢ï¼å ¶ä¸%déæ£ç¡®ï¼æ£ç¡®ç为%f\n",sum,right,precent);
break;
default:printf("æ¨çè¾å ¥æ误ï¼è¯·éæ°è¾å ¥\n");choose();
}
}
int ans(int x,int y,int choice)
{
switch(choice)
{
case 1:z=x+y;break;
case 2:z=x-y;break;
case 3:z=x*y;break;
case 4:z=x/y;break;
}
return( z);
}
void yunsuan()
{
suiji();
printf("%d%c%d=",x,fuhao,y);
z=ans(x,y,choice);
answer=scan();
if(z==answer)
{
printf("æ£ç¡®\n");
right++;sum++;
yunsuan();
}
else if(answer==9999) choose();
else
{
printf("ä¸æ£ç¡®, æ£ç¡®çæ¡ä¸º%5d\n",z);
sum++;
yunsuan();
}
}
void main()
{
printf("欢è¿æ¥å°ååè¿ç®æµè¯ç³»ç»\n");
choose();
while(choice!=5)
yunsuan();
}追é®
ä½ è¿ä¸ªä¸æ¯ç¨é£ä¸ªç«å¼è®¡ç®çæ¹æ³å§
追çç«å¼è¿ç®ï¼è¿ä¸ªå°±æ¯ååè¿ç®å
追é®ææ³ä½¿ç¨çæ¯ç±»ä¼¼ç«å¼è®¡ç®çæ¹æ³è®¡ç®ï¼å°±æ¯ä¸ä½ä¸ä½ç计ç®ï¼ææ¯ä¸ä½åå«è®¡ç®æ以å¾æè¾å ¥çæ°å解æå 个æ°ææç
追çå åå¯ä»¥â¦ä¹é¤æä¹å¼
é£å¿«æå¼åæ°è½¯ä»¶äºâ¦è°å¨è¿ç»ä½ å
追é®æåªç¥éæä¹ç®ï¼ä¸ç¥éæä¹ç¼ã
追çä½ æ²¡äºå¼è¿ä¸ªç¨åºï¼ä½ æ¬èµ200估计è¿æ人â¦ç¨åºå¤ªéº»ç¦
追é®ç¨åºä¸æ¯å¤ªé¾æä¹ï¼ä¸»è¦æ¯é£ç§æ³æ³å¼æç½å°±å¥½äº
温馨提示:答案为网友推荐,仅供参考