本文主要是介绍C语言程序设计苏小红课后习题答案7.14.5,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//生成随机符号
char Charop()
{int op;op = rand() % 4 + 1;switch (op){case 1:return '+';case 2:return '-';case 3:return '*';case 4:return '/';}return 0;
}
//生成随机数(1到10)
int number()
{int a;a=rand() % 10 + 1;return a;
}
int Calculate(int x, char op,int y)
{int a, b, c, d;a = x + y;b = x - y;c = x * y;d = x / y;switch (op){case '+': return a;case '-': return b;case '*': return c;case '/': return d;default:return 0;}
}int fun()
{int answer,counter=0,grade=0;int x, y,m,n;char op;for (int i = 1;i <= 10;i++){x = number();y = number();op=Cherop(); printf("%d%c%d=", x, op,y);scanf("%d", &answer);if (answer == Calculate(x, op, y)){printf("Right!\n");grade++;} elseprintf("Wrong!\n");counter++;}printf("grade=%d\n", grade);if (grade * 10 < 75){printf("Please again\n");return fun();}elsereturn 0;}
int main()
{fun();return 0;
}
这篇关于C语言程序设计苏小红课后习题答案7.14.5的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!