小学生四则运算
Posted gxcblog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了小学生四则运算相关的知识,希望对你有一定的参考价值。
设计思想:
利用c++设计,采用release的编译模式,从而最简单的实现程序发布。
源程序代码:
#include<stdio.h>
#include<stdlib.h>
#include <time.h>
main()
{
int a,b,c,d,e,f,k,i,n,t,N,re,re1,re2u,re2d,re3u,re3d,hua,hua1;
srand(time(NULL));
do{
printf(" 请输入数字类型(1.整数 2.真分数) 0为退出程序: ");
scanf("%d",&n);
printf(" 请输入题目个数:");
scanf("%d",&N);
switch(n)
{
case 1:
{
for(i=0;i<N;i++)
{
a=rand()%100+1;
b=rand()%100+1;
k=rand()%4+1;
printf("%d",a);
switch(k)
{
case 1:printf("+");
re=a+b;
break;
case 2:printf("-");
re=a-b;
break;
case 3:printf("×");
re=a*b;
break;
case 4:printf("÷");
re=a/b;
break;
}
printf("%d= ",b);
scanf("%d",&re1);
if(re == re1)
{
printf("T");
printf(" ");
}
else
printf("F");
printf(" ");
}
break;
}
break;
case 2:
{
for(i=0;i<N;i++)
{
c=rand()%100+1;
d=rand()%100+1;
e=rand()%100+1;
f=rand()%100+1;
k=rand()%4+1;
if(c>d)
{
t=c;
c=d;
d=t;
}
if(e>f)
{
t=e;
e=f;
f=t;
}
if(c%d==0)
{
hua=c/d;
printf("%d",hua);
}
else if(d%c==0)
{
hua=d/c;
printf("1/%d",hua);
}
else
{
printf("%d/%d",c,d);
}
switch(k)
{
case 1:printf("+");
re2u=c*f+d*e;
re2d=d*f;
if(re2u%re2d==0)
{
re2u=re2u/re2d;
re=re2u;
}
else if(re2d%re2u==0)
{
re2d=re2d/re2u;
re2u=1;
}
else
{
re2u=re2u;
re2d=re2d;
}
break;
case 2:printf("-");
re2u=c*f-d*e;
re2d=d*f;
if(re2u%re2d==0)
{
re2u=re2u/re2d;
re2d=1;
}
else if(re2d%re2u==0)
{
re2d=re2d/re2u;
re2u=1;
}
else
{
re2u=re2u;
re2d=re2d;
}
break;
case 3:printf("×");
re2u=c*e;
re2d=d*f;
if(re2u%re2d==0)
{
re2u=re2u/re2d;
re2d=1;
}
else if(re2d%re2u==0)
{
re2d=re2d/re2u;
re2u=1;
}
else
{
re2u=re2u;
re2d=re2d;
}
break;
case 4:printf("÷");
re2u=c*f;
re2d=d*e;
if(re2u%re2d==0)
{
re2u=re2u/re2d;
re2d=1;
}
else if(re2d%re2u==0)
{
re2d=re2d/re2u;
re2u=1;
}
else
{
re2u=re2u;
re2d=re2d;
}
break;
}
if(e%f==0)
{
hua1=e/f;
printf("%d= ",hua1);
}
else if(f%e==0)
{
hua1=f/e;
printf("1/%d= ",hua1);
}
else
{
printf("%d/%d= ",e,f);
}
scanf("%d/%d",&re3u,&re3d);
if(re2u == re3u&&re2d == re3d)
{
printf("T");
printf(" ");
}
else
printf("F");
printf(" ");
}
break;
}
break;
}
}
while(n!=-1);
}
运行结果
以上是关于小学生四则运算的主要内容,如果未能解决你的问题,请参考以下文章