用C语言编写一个简单加减乘除的程序
3个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
main()
{
int a,b,c,d,result,i;
char f[]={'+','-','*','/'};
while(1)
{
srand(time(NULL));
a=rand()%100;
b=rand()%100;
c=rand()%4;
switch (c)
{
case 0: d=a+b;break;
case 1: d=a-b;break;
case 2: d=a*b;break;
case 3: d=a/b;break;
}
printf("输入结果:%d%c%d=",a,f[c],b);
i=0;
while (i<2)
{
scanf("%d",&result);
if (result==d&&i<2)
{printf("你答对了^_^\n"); break; }
else i++,printf("你答错了%d次:",i);
if (i==2) {printf("\n答案:%d\n",d);}
}
}
}
#include <stdlib.h>
#include <time.h>
main()
{
int a,b,c,d,result,i;
char f[]={'+','-','*','/'};
while(1)
{
srand(time(NULL));
a=rand()%100;
b=rand()%100;
c=rand()%4;
switch (c)
{
case 0: d=a+b;break;
case 1: d=a-b;break;
case 2: d=a*b;break;
case 3: d=a/b;break;
}
printf("输入结果:%d%c%d=",a,f[c],b);
i=0;
while (i<2)
{
scanf("%d",&result);
if (result==d&&i<2)
{printf("你答对了^_^\n"); break; }
else i++,printf("你答错了%d次:",i);
if (i==2) {printf("\n答案:%d\n",d);}
}
}
}
展开全部
#include
<stdio.h>
#include
<stdlib.h>
#include
<time.h>
main()
{
int
a,b,c,d,result,i;
char
f[]={'+','-','*','/'};
while(1)
{
srand(time(NULL));
a=rand()%100;
b=rand()%100;
c=rand()%4;
switch
(c)
{
case
0:
d=a+b;break;
case
1:
d=a-b;break;
case
2:
d=a*b;break;
case
3:
d=a/b;break;
}
printf("输入结果:%d%c%d=",a,f[c],b);
i=0;
while
(i<2)
{
scanf("%d",&result);
if
(result==d&&i<2)
{printf("你答对了^_^\n");
break;
}
else
i++,printf("你答错了%d次:",i);
if
(i==2)
{printf("\n答案:%d\n",d);}
}
}
}
<stdio.h>
#include
<stdlib.h>
#include
<time.h>
main()
{
int
a,b,c,d,result,i;
char
f[]={'+','-','*','/'};
while(1)
{
srand(time(NULL));
a=rand()%100;
b=rand()%100;
c=rand()%4;
switch
(c)
{
case
0:
d=a+b;break;
case
1:
d=a-b;break;
case
2:
d=a*b;break;
case
3:
d=a/b;break;
}
printf("输入结果:%d%c%d=",a,f[c],b);
i=0;
while
(i<2)
{
scanf("%d",&result);
if
(result==d&&i<2)
{printf("你答对了^_^\n");
break;
}
else
i++,printf("你答错了%d次:",i);
if
(i==2)
{printf("\n答案:%d\n",d);}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include
<stdio.h>
#include
<stdlib.h>
#include
<time.h>
main()
{
int
a,b,c,d,result,i;
char
f[]={'+','-','*','/'};
while(1)
{
srand(time(NULL));
a=rand()%100;
b=rand()%100;
c=rand()%4;
switch
(c)
{
case
0:
d=a+b;break;
case
1:
d=a-b;break;
case
2:
d=a*b;break;
case
3:
d=a/b;break;
}
printf("输入结果:%d%c%d=",a,f[c],b);
i=0;
while
(i<2)
{
scanf("%d",&result);
if
(result==d&&i<2)
{printf("你答对了^_^\n");
break;
}
else
i++,printf("你答错了%d次:",i);
if
(i==2)
{printf("\n答案:%d\n",d);}
}
}
}
<stdio.h>
#include
<stdlib.h>
#include
<time.h>
main()
{
int
a,b,c,d,result,i;
char
f[]={'+','-','*','/'};
while(1)
{
srand(time(NULL));
a=rand()%100;
b=rand()%100;
c=rand()%4;
switch
(c)
{
case
0:
d=a+b;break;
case
1:
d=a-b;break;
case
2:
d=a*b;break;
case
3:
d=a/b;break;
}
printf("输入结果:%d%c%d=",a,f[c],b);
i=0;
while
(i<2)
{
scanf("%d",&result);
if
(result==d&&i<2)
{printf("你答对了^_^\n");
break;
}
else
i++,printf("你答错了%d次:",i);
if
(i==2)
{printf("\n答案:%d\n",d);}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询