#includestdio.h#include stdlib.h#includeconio.h#includetime.hint main(){ int r=0; int a=0; int b=0; int p=0; int q=0; int g=0; int h=0; int m=0; int i,t,n,k,s,c; ...
#include<stdio.h>
#include <stdlib.h>
#include<conio.h>
#include<time.h>
int main()
{
int r=0;
int a=0;
int b=0;
int p=0;
int q=0;
int g=0;
int h=0;
int m=0;
int i,t,n,k,s,c;
scanf("%d",&n);
srand((unsigned)time(NULL));
for(i=0;i<n;i++)
{
a=rand()%100;
b=rand()%100;
p=rand()%100;
q=rand()%100;
g=rand()%100;
h=rand()%100;
m=rand()%8;
if(q<p)
{
k=q;
q=p;
p=k;
}
if(h<g)
{
s=g;
g=h;
h=s;
}
if(a<b)
{
t=a;
a=b;
b=t;
}
switch(m)
{
case 0:
printf("\n%d+%d=",a,b,a+b);
r=a+b;
break;
case 1:
printf("\n%d-%d=",a,b,a-b);
r=a-b;
break;
case 2:
printf("\n%d*%d=",a,b,a*b);
r=a*b;
break;
case 3:
printf("\n%d/%d=",a,b,a/b);
r=a/b;
break;
case 4:
printf("\n%d/%d+%d/%d=",p,q,g,h,p/q+g/h);
r=p/q+g/h;
break;
case 5:
printf("\n%d/%d-%d/%d=",p,q,g,h,p/q-g/h);
r=p/q-g/h;
break;
case 6:
printf("\n%d/%d*%d/%d=",p,q,g,h,p/q*g/h);
r=p/q*g/h;
break;
case 7:
printf("\n%d/%d/%d/%d=",p,q,g,h,p/q/g/h);
r=p/q/g/h;
break;
default:
printf("something is wrong!\n");
break;
}
printf("\n");
scanf("%d",&c);
if(c==r)
printf("right\n\n");
else
{
printf("wrong\n\n");
}
return 0;
}
本文标题为:既可以支持整数四则运算,也可以支持分数四则运算,可定制出题数量的c语言程序
基础教程推荐
- character-encoding – Linux中最常见的C语言编码(和Unix?) 2023-11-21
- g++: const 丢弃限定符 2022-10-07
- Qt数据库应用之实现通用数据库请求 2023-03-18
- C语言植物大战数据结构二叉树递归 2023-04-09
- 纯C++代码详解二叉树相关操作 2023-05-15
- C语言的三种条件判断语句你都了解吗 2023-03-05
- C语言数组长度的计算方法实例总结(sizeof与strlen) 2023-04-26
- 05-C语言进阶——动态内存管理 2023-11-20
- 利用QT设计秒表功能 2023-05-30
- VisualStudio2010安装教程 2023-01-05
