c语言编程题,题目如图,麻烦会的亲写一下过程,谢谢!
3个回答
展开全部
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(void)
{
const char operators[4] = {'+','-','*','/'};
double number1;
double number2;
double result = 0;//计算结果变量
char rand_operator;
srand((unsigned)time(NULL));//设置时间种子
rand_operator = operators[rand()%4];//随机抽取运算符号
number1 = (double)(rand())/100;//产生小数为两位的随机小数
number2 = (double)(rand())/100;
switch(rand_operator)
{
case '+':
result = number1 + number2;
break;
case '-':
result = number1 - number2;
break;
case '*':
result = number1 * number2;
break;
case '/':
result = number1 / number2;
break;
default:
printf("error!\n");//如果出错,那么退出程序
exit(-1);
}
printf("%.2f %c %.2f = %.2f\n",number1,rand_operator,number2,result);//打印结果
return 0;
}
望采纳!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/*
编写一个产生随机简单表达式的程序(如3.4+196.7),形式如下:number1 operator number2
随机产生 number 和 operator
number: 一位小数
operator:+ - * /
计算结果以两位小数显示
*/
/*
double cout =0.0;
//number1 ,menber2随机产生
double number1 ,menber2;
//随机产生操作符
char oper[5]="+-*/";
int a =rand()%4;
char ch = oper [a];
switch ( ch)
{
case '+':cout =number1 +menber2;
case '-':cout =number1 -menber2;
case '*':cout =number1 *menber2;
case '/':cout =number1 +menber2;
}
*/
编写一个产生随机简单表达式的程序(如3.4+196.7),形式如下:number1 operator number2
随机产生 number 和 operator
number: 一位小数
operator:+ - * /
计算结果以两位小数显示
*/
/*
double cout =0.0;
//number1 ,menber2随机产生
double number1 ,menber2;
//随机产生操作符
char oper[5]="+-*/";
int a =rand()%4;
char ch = oper [a];
switch ( ch)
{
case '+':cout =number1 +menber2;
case '-':cout =number1 -menber2;
case '*':cout =number1 *menber2;
case '/':cout =number1 +menber2;
}
*/
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
#include <math.h>
void main()
{
double number1,number2;
double result;
char operator;
number1=rand()*100;
number2=rand()*200;
switch(rand()*4)
{
case 0: operator='+';result=number1+number2;break;
case 1: operator='-';result=number1-number2;break;
case 2: operator='*';result=number1*number2;break;
default: operator='/';result=number1/number2;break;
}
printf("%5.2f%c%5.2f=%10.2f\n",number1,operator,number2,result);
}
怎么又是你?
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询