C语言程序设计(第3版)P143页小学生计算机辅助教学系统

任务1

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main()
{
	int m,n,counter=0,p,x;
	srand(time(NULL));
	m=rand()%10+1;
	n=rand()%10+1;
	do{
		p=m*n;
		printf("%d*%d=?\n",m,n);
		scanf("%d",&x);
		if(p==x)
			printf("Right!\n");
		if(p!=x)
		{
			printf("Wrong! Please try again.\n");
		}
	}while(x!=p);

	return 0;
}

任务2

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main()
{
	int m,n,counter=0,p,x;
	srand(time(NULL));
	m=rand()%10+1;
	n=rand()%10+1;
	do{
		p=m*n;
		printf("%d*%d=?\n",m,n);
		scanf("%d",&x);
		if(p==x)
			printf("Right!\n");
		if(p!=x)
		{
			counter++;
			if(counter<=2)
			{
				printf("Wrong! Please try again.\n");
			}
			else
				printf("Wrong!You have tried three times! Test over!\n");
		}
	}while(x!=p&&counter<3);

	return 0;
}

任务三

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main()
{
	int m,n,counter=0,p,x;
	float l=0,k;
	srand(time(NULL));
	do{
		m=rand()%10+1;
		n=rand()%10+1;
		p=m*n;
		printf("%d*%d=?\n",m,n);
		scanf("%d",&x);
		counter++;
		if(p==x)
		{
			l++;
			printf("Right!\n");
		}
		if(p!=x)
		{
			printf("Wrong!\n");
		}
	}while(counter<10);
	k=100*(float(l)/10);
	printf("正确率:%.f%%\n",k);

	return 0;
}

任务四

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main()
{
	system("color 5F");
	int m,n,counter=0,p,x,y,t,term,v;
	float l=0,k;
	char h;
	srand((unsigned)time(NULL));
	srand(time(NULL));

	do{
		t=rand()%4;
		m=rand()%10+1;
		n=rand()%10+1;
		if(t==0)
		{
			h='+';
			p=m+n;
		}
		if(t==1)
		{
			h='-';
			if(m<n)
			{
				term=m;
				m=n;
				n=term;
			}
			p=m-n;
		}
		if(t==2)
		{
			h='*';
			p=m*n;
		}
		if(t==3)
		{
			h='/';
			do{
				m++;
			}while(m%n!=0);
			p=m/n;
		}
		printf("%d%c%d=?\n",m,h,n);
		do{
			printf("请输入您计算答案:");
			y=scanf("%d",&x);
			switch(y)
			{
			case 0:
				while(getchar()!='\n');
				v=1;
				break;
			case 1:
				if(n>=0)
					v=0;
			}
		}while(v==1);
		counter++;
		if(p==x)
		{
			l++;
			printf("Right!\n");
		}
		if(p!=x)
		{
			printf("Wrong!\n");
		}
	}while(counter<10);
	k=100*(float(l)/10);
	printf("正确率:%.f%%\n您的分数为%.f\n",k,k);
	return 0;
}

任务五

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main()
{
	system("color 5F");
	int m,n,counter=0,p,x,y,t,term,v;
	float l=0,k;
	char h;
	srand((unsigned)time(NULL));
	srand(time(NULL));
	do{
		do{
			t=rand()%4;
			m=rand()%10+1;
			n=rand()%10+1;
			if(t==0)
			{
				h='+';
				p=m+n;
			}
			if(t==1)
			{
				h='-';
				if(m<n)
				{
					term=m;
					m=n;
					n=term;
				}
				p=m-n;
			}
			if(t==2)
			{
				h='*';
				p=m*n;
			}
			if(t==3)
			{
				h='/';
				do{
					m++;
				}while(m%n!=0);
				p=m/n;
			}
			printf("%d%c%d=?\n",m,h,n);
			do{
				printf("请输入您计算答案:");
				y=scanf("%d",&x);
				switch(y)
				{
				case 0:
					while(getchar()!='\n');
					v=1;
					break;
				case 1:
					if(n>=0)
						v=0;
				}
			}while(v==1);
			counter++;
			if(p==x)
			{
				l++;
				printf("Right!\n");
			}
			if(p!=x)
			{
				printf("Wrong!\n");
			}
		}while(counter<10);
		k=100*(float(l)/10);
		printf("正确率:%.f%%\n您的分数为%.f\n",k,k);
		counter=0,l=0;
		if(k<75)
			printf("您的正确率不到75%%,请在做一遍.\n");
	}while(k<75);
	return 0;
}

任务六

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main()
{
	system("color 5F");
	int m,n,counter=0,p,x,y,t,term,v;
	float l=0,k;
	char h;
	srand((unsigned)time(NULL));
	srand(time(NULL));
	do{
		do{
			t=rand()%4;
			m=rand()%10+1;
			n=rand()%10+1;
			if(t==0)
			{
				h='+';
				p=m+n;
			}
			if(t==1)
			{
				h='-';
				if(m<n)
				{
					term=m;
					m=n;
					n=term;
				}
				p=m-n;
			}
			if(t==2)
			{
				h='*';
				p=m*n;
			}
			if(t==3)
			{
				h='/';
				do{
					m++;
				}while(m%n!=0);
				p=m/n;
			}
			printf("%d%c%d=?\n",m,h,n);
			do{
				printf("请输入您计算答案:");
				y=scanf("%d",&x);
				switch(y)
				{
				case 0:
					while(getchar()!='\n');
					v=1;
					break;
				case 1:
					if(n>=0)
						v=0;
				}
			}while(v==1);
			counter++;
			if(p==x)
			{
				l++;
				if(t==0)
					printf("Very good!\n");
				if(t==1)
					printf("Excellent!\n");
				if(t==2)
					printf("Nice work!\n");
				if(t==3)
					printf("Keep up the good work!\n");
			}
			if(p!=x)
			{
				if(t==0)
					printf("No.Please try again.\n");
				if(t==1)
					printf("Wrong.Try once more.\n");
				if(t==2)
					printf("Don't give up\n");
				if(t==3)
					printf("Not correct.Keep trying.\n");
			}
		}while(counter<10);
		k=100*(float(l)/10);
		printf("正确率:%.f%%\n您的分数为%.f\n",k,k);
		counter=0,l=0;
		if(k<75)
			printf("您的正确率不到75%%,请在做一遍.\n");
	}while(k<75);
	return 0;
}



  • 38
    点赞
  • 116
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值