#include<stdio.h>
#include<stdlib.h>
#include <time.h>
int add(int x,int y)
{printf("%d + %d =",x,y)
return x+y}
int sub(int x,int y)
{printf("%d - %d =",x,y)return x-y}
int mul(int x,int y)
{printf("%d * %d =",x,y)return x*y}
int dec(int x,int y)
{printf("%d / %d =",x,y)return x/y}
int mod(int x,int y)
{printf("%d % %d =",x,y)return x%y}
void fun(int f)
{
int n,x,y,z,t,result,sum=0
srand((unsigned)time(NULL))
printf("请选择答题的个数:\n")
scanf("%d",&n)
for(int i=0i<ni++)
{
x=rand()%100
y=rand()%100
if(x<y &&f==2)
{t=xx=yy=t}
if(f==3||f==4)
{while(!x){x=rand()%100}
while(!y){y=rand()%100}}
switch(f)
{
case 1:
result=add(x,y)break
case 2:
result=sub(x,y)break
case 3:
result=mul(x,y)break
case 4:
result=dec(x,y)break
case 5:
result=mod(x,y)break
}
scanf("%d",&z)
if(result==z)
{printf("正确!\n")sum++}
else
printf("错误!应该是%d\n",result)
}
printf("\行告n正确率为%f%%\n/////////////////////////////////\n\n",100.0*sum/n)
fflush(stdin)
}
void main()
{
printf("/////////////////////////////////\n")
printf(" 计算软件\n")
printf("//////////////////////////////////\n\n")
int ch
while(1)
{
printf("请选择圆带燃题型--加(1),减(2),乘(3),除(4),求余(5),退出(6): ")
scanf("%d",&ch)
if(ch==1||ch==2||ch==3||ch==4||ch==5)
fun(ch)
else if(ch==6)
exit(0)
else
printf("错误!\n")
}
}
不懂请追问#include <stdio.h>
#include <string.h>
int main()
{
__int64 n,m
int c,jin,bg,i
int num[21]
while(scanf("%lld",&n)==1)
{
m = n
memset(num,0,sizeof(num))
c = 0
while(n>0&&c<孙岁卖则逗21)
{
switch(n%3)
{
case 0:
n/=3
break
case 1:
num[c] = 1
n/=3
break
case 2:
num[c] = -1
n/=3
n++
break
case 3:
n/=3
n++
break
}
c++
}
if(c==21&&n!=0)
{
printf("No solution.\n")
}
else
{
bg = 1
printf("%lld =",m)
for(i=0i<21i++)
{
if(num[i]==1)
{
if(!bg) printf(" +")
printf(" 3^%d",i)
bg = 0
}
else if(num[i]==-1)
{
printf(" - 3^%d"雀宽,i)
bg = 0
}
}
printf("\n")
}
printf("\n")
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)