随机生成10以内四则运算式,由用户输入计算结果,程序判断对错,输入00结束程序。输出总题数和正确题数。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string.h>
int right;
void Menu();//菜单说明
void Calculation_formula();//随机生成运算式
void swap(int *a,int *b);//交换数值
void reverse(char str[],int n);//数组逆转
int main()
{
int number=0,accepted=0;
//number是总的测试题数,accepted是正确题数
int i,length,true_result;
char result[5];
Menu();
while(1){
i=0;
true_result=0;
Calculation_formula();
scanf("%s",result);//以数字字符数组形式保存输入的结果
if(result[1]=='0'&&result[0]=='0')//结束标志
break;
length=strlen(result);
reverse(result,length);
while(result[i]!='\0'){//将数字字符串转换成对应数值
true_result+=(result[i]-48)*pow(10,i);