用c语言编写小学生四则运算!
发布网友
发布时间:2022-04-23 23:40
我来回答
共3个回答
热心网友
时间:2023-10-13 21:31
#include <stdio.h> /*小学生数学练习*/
int randd(void);
int randd1(void);
int rand1(void);
int rand2(void);
float randf(float a,float b);
main()
{
float i,k,a,b;
int x,c,=0,cu=0,j,w,f;
srand(time(NULL));
printf("选择难度\n");
printf("1是1位数 2是2位数\n");
printf("目前只支持3位数\n");
scanf("%d",&x);
printf("选择算法 1加法 2减法 3乘法 4除法 5混合\n");
printf("除法只求整数部分\n");
scanf("%d",&w);
for(j=1;j<=20;j++)
{
switch(x) /*选择难度*/
{
case 1 : a=randd(); b=randd();
break;
case 2 : a=rand1(); b=rand1();
break;
case 3 : a=rand2(); b=rand2();
break;
}
c=randd1();
switch(w) /*选择算法*/
{case 1 : k=a+b; break;
case 2 : k=a-b; break;
case 3 : k=a*b; break;
case 4 : f=a/b;k=f; break;
case 5 : k=randf(a,b); break;
}
printf("%.0f",k);
printf("How much is %.0f times %.0f ?",a,b);
scanf("%f",&i);
while(i!=k)
{
cu++;
c=randd1();
switch(c)
{
case 1 : printf("NO,please try again.\n");break;
case 2 : printf("Wrong Try once more.\n");break;
case 3 : printf("Don't give up.\n");break;
default :printf("NO.keep trying.\n");break;
}
printf("How much is %0.f times %0.f ?",a,b);
scanf("%f",&i);
}
++;
switch(c)
{
case 1 : printf("very good!\n");break;
case 2 : printf("Excellent!\n");break;
case 3 :printf("Nice work!\n");break;
default :printf("keep up the good work!\n");break;
}
if(cu+>=10)/*10题正确75%以下帮助*/
{
if(<=(cu+)*(75.0/100.0))
printf("help");break;
}
}
}
int randd(void)
{
int a;
a=1+rand()%9;
return a;
}
int rand1(void)
{
int a;
a=10+rand()%89;
return a;
}
int rand2(void)
{
int a;
a=100+rand()%899;
return a;
}
int randd1(void)
{
int a;
a=1+rand()%4;
return a;
}
float randf(float a,float b)/*混合*/
{
int c,f;
float k;
c=randd1();
switch(c)
{
case 1 : k=a+b;printf("求加\n");break;
case 2 : k=a-b;printf("求减\n");break;
case 3 : k=a*b;printf("求乘\n");break;
case 4 : f=a/b;k=f;printf("求除。只求整数部分\n");break;
}
return k;
}
这是我以前写的作业你自己看着改吧~
热心网友
时间:2023-10-13 21:32
#include <stdio.h> /*小学生数学练习*/
int randd(void);
int randd1(void);
int rand1(void);
int rand2(void);
float randf(float a,float b);
main()
{
float i,k,a,b;
int x,c,=0,cu=0,j,w,f;
srand(time(NULL));
printf("选择难度\n");
printf("1是1位数 2是2位数\n");
printf("目前只支持3位数\n");
scanf("%d",&x);
printf("选择算法 1加法 2减法 3乘法 4除法 5混合\n");
printf("除法只求整数部分\n");
scanf("%d",&w);
for(j=1;j<=20;j++)
{
switch(x) /*选择难度*/
{
case 1 : a=randd(); b=randd();
break;
case 2 : a=rand1(); b=rand1();
break;
case 3 : a=rand2(); b=rand2();
break;
}
c=randd1();
switch(w) /*选择算法*/
{case 1 : k=a+b; break;
case 2 : k=a-b; break;
case 3 : k=a*b; break;
case 4 : f=a/b;k=f; break;
case 5 : k=randf(a,b); break;
}
printf("%.0f",k);
printf("How much is %.0f times %.0f ?",a,b);
scanf("%f",&i);
while(i!=k)
{
cu++;
c=randd1();
switch(c)
{
case 1 : printf("NO,please try again.\n");break;
case 2 : printf("Wrong Try once more.\n");break;
case 3 : printf("Don't give up.\n");break;
default :printf("NO.keep trying.\n");break;
}
printf("How much is %0.f times %0.f ?",a,b);
scanf("%f",&i);
}
++;
switch(c)
{
case 1 : printf("very good!\n");break;
case 2 : printf("Excellent!\n");break;
case 3 :printf("Nice work!\n");break;
default :printf("keep up the good work!\n");break;
}
if(cu+>=10)/*10题正确75%以下帮助*/
{
if(<=(cu+)*(75.0/100.0))
printf("help");break;
}
}
}
int randd(void)
{
int a;
a=1+rand()%9;
return a;
}
int rand1(void)
{
int a;
a=10+rand()%89;
return a;
}
int rand2(void)
{
int a;
a=100+rand()%899;
return a;
}
int randd1(void)
{
int a;
a=1+rand()%4;
return a;
}
float randf(float a,float b)/*混合*/
{
int c,f;
float k;
c=randd1();
switch(c)
{
case 1 : k=a+b;printf("求加\n");break;
case 2 : k=a-b;printf("求减\n");break;
case 3 : k=a*b;printf("求乘\n");break;
case 4 : f=a/b;k=f;printf("求除。只求整数部分\n");break;
}
return k;
热心网友
时间:2023-10-13 21:32
这都这么简单,你有没有学过C啊!