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

#include<stdio.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
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");
		
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_45725923/article/details/123528344