该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include 

#include 

#include 

void Menu(void)

{

printf("1,加法 2,减法 3,乘法 4,除法 5,退出\n");

printf("请选择题目类型:");

}

int Plus(void)

{

int a, b;

a = rand() % 10 + 1;

b = rand() % 10 + 1;

printf("%-2d + %-2d = ", a, b);

return a + b;

}

int Sub(void)

{

int a, b;

a = rand() % 10 + 1;

b = rand() % 10 + 1;

printf("%-2d - %-2d = ", a, b);

return a - b;

}

int Mult(void)

{

int a, b;

a = rand() % 10 + 1;

b = rand() % 10 + 1;

printf("%-2d * %-2d = ", a, b);

return a * b;

}

int Div(void)

{

int a, b;

while(a % b != 0)

{

a = rand() % 10 + 1;

b = rand() % 10 + 1;

}

printf("%-2d / %-2d = ", a, b);

return a / b;

}

int Subject(int type)

{

switch(type)

{

case 1: return Plus();

case 2: return Sub();

case 3: return Mult();

case 4: return Div();

}

}

void Do(int type)

{

int count = 0, score = 0, key, answer;

while(count 

{

key = Subject(type);

scanf("%d", &answer);

if(key == answer)

score += 10;

count++;

}

printf("%d\n", score);

}

int main(void)

{

int  type, score;

while(1)

{

Menu();

scanf("%d", &type);

if(type == 5) return 0;

Do(type);

system("pause");

system("cls");

}

}

更多推荐