C 随机出十道加减法的练习题并自动批改

#include
#include
#include
#include
int main(){
	int a,b,c,d,ch,right,answer;
	srand(time(NULL));
	for(int i=0;i<10;i++){   
		a=rand()%10;
		b=rand()%10;
		ch=rand()%2+1;
		switch(ch){
			case 1: printf("%d + %d = \n",a,b) ; break;       //加法
			case 2: printf("%d - %d = \n",a,b) ; break;//减法 
		}
		if(ch==1)
			right=a+b;
		else right =a-b;
		printf("请输入您的答案:\n");
		scanf("%d",&answer); 
		if(right == answer)
			printf("计算正确!\n");
		else 	printf("计算错误!\n");
		
	}
}

你可能感兴趣的:(c语言,开发语言)