#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include <math.h>
void jiaf();
void jianf();
void cf();
void chuf();
void gj();
int i;
void main()
{
int choose;
while(1)
{
printf("===================================\n");
printf("欢迎使用本程序 请选择功能:\n");
printf("1 简单加法 2 简单减法\n");
printf("3 简单乘法 4 简单除法\n");
printf("5 高级算法 \n");
printf("请输入你的选择(1--5):");
scanf("%d",&choose);
switch(choose)
{ case 1:jiaf();break;
case 2:jianf();break;
case 3:cf();break;
case 4:chuf();break;
case 5:gj();break;
}
}
}
void jiaf()
{
int a,b,c,h;
srand((unsigned)time(0));
printf("\n加法题:");
for(int i=0;i<2;i++)
{
printf("");
a=rand()% 100;
printf("%d",a);
b=rand()% 100;
printf(" + ");
printf("%d",b);
printf(" = ");
h=a+b;
scanf("%d",&c);
if(c==h)
{
printf("\n回答正确!");
}
else
printf("\n回答错误!");
printf("\n");
}
}
void jianf()
{
int a,b,c,h;
srand((unsigned)time(0));
printf("\n减法题:");
for( i=0;i<2;i++)
{
printf("");
a=rand()% 100;
printf("%d",a);
b=rand()% 100;
printf(" - ");
printf("%d",b);
printf(" = ");
h=a-b;
scanf("%d",&c);
if(c==h)
{
printf("\n回答正确!");
}
else
printf("\n回答错误!");
printf("\n");
}
}
void cf()
{
int a,b,c,h;
srand((unsigned)time(0));
printf("\n乘法题:");
for( i=0;i<2;i++)
{
printf("");
a=rand()% 10;
printf("%d",a);
b=rand()% 10;
printf(" * ");
printf("%d",b);
printf(" = ");
h=a*b;
scanf("%d",&c);
if(c==h)
{
printf("\n回答正确!");
}
else
printf("\n回答错误!");
printf("\n");
}
}
void chuf()
{
int a,b;
float c,h;
srand((unsigned)time(0));
printf("\n除法题(结果保留后两位小数):");
for( i=0;i<2;i++)
{
printf("");
a=rand()% 10;
printf("%d",a);
b=rand()% 10;
while(b==0)
{
b=rand()% 10;
}
printf(" / ");
printf("%d",b);
printf(" = ");
h=(a*1.0)/b;
h=( (float)( (int)( (h+0.005)*100 ) ) )/100;
scanf("%f",&c);
if(c==h)
{
printf("\n回答正确!");
}
else
printf("\n回答错误!");
printf("\n");
}
}
void gj()
{
int p;
int l,a,b,c,h,k;
srand((unsigned)time(0));
p=rand()% 10;
if(p>5)
{
p=0;
}else
p=1;
switch(p)
{
case 0:
a=rand()% 10;
p=rand()% 10;
if(p>5)
{
p=0;
}
else
p=1;
switch(p)
{
case 0:
b=rand()% 10;
c=rand()% 10;
printf("(%d+%d)*%d=",a,b,c);
h=(a+b)*c;
scanf("%d",&k);
if(k==h)
{
printf("\n回答正确!");
}
else
printf("\n回答错误!");
printf("\n");break;
case 1:
b=rand()% 10;
c=rand()% 10;
printf("(%d-%d)*%d=",a,b,c);
h=(a-b)*c;
scanf("%d",&k);
if(k==h)
{
printf("\n回答正确!");
}
else
printf("\n回答错误!");
printf("\n");break;
}break;
case 1:a=rand()% 10;
b=rand()% 10;
c=rand()% 10;
printf("%d*(%d+%d)=",a,b,c);
h=a*(b+c);
scanf("%d",&k);
if(k==h)
{
printf("\n回答正确!");
}
else
printf("\n回答错误!");
printf("\n");break;
}
}