编程,输入两个实数 a,b,再输入一个运算符(可以是+,-,*或/),根据运算符计算并输出a,b两个数的和,差积和商. 编程,要求输入两个实数,再选择+,-,×,÷四个按钮之一,根...

   www.gaoxiao88.net
#include "stdio.h"
void main()
{
float a,b,result;
char ch;
printf("\nplease input two numbers(a, b):");
scanf("%f,%f",&a,&b);//注意在输入时这里要用","分开
getchar();// 目的是接受一个回车符
printf("\nplease input a operator (+,-*,/):");
scanf("%c",&ch);
switch(ch)
{
case '+': result=a+b;break;
case '-': result=a-b;break;
case '*': result=a*b;break;
case '/': result=a/b;break;
default:break;

}
printf("\n%f %c %f=%f",a,ch,b,result);
printf("\n");
}

void main()
{
int a,b; //运算数
char c; //运算符
scanf("%d %d %c",&a,&b,&c);//从键盘输入得到a,b,c 的值
switch (c)
{
case '+': printf("%d",(a+b)); break;
case '-': printf("%d",(a-b)); break;
case '*': printf("%d",(a*b)); break;
case '/': printf("%f",(a/b)); break;

default: printf("运算符错误!"); break;
}
}

main()
{ int a,b;
scanf(“%a%b”,&a,&b);
printf("%d",(a+b));
}

用什么?C?

豁哥哥!

用c++编写一个程序,输入两个实数和一个四则运算符(+,-,*,/),根据运算符执行相应的运算并输出结果。

#includeint main(){double a,b,c; char op; scanf("%lf%c%lf",&a,&op,&b); if(op=='+')c=a+b; else if (op=='-')c=a-b; else if (op=='*')c=a*b; else if (op=='/') if(b)c=a/b; else {printf("除数不能为0!
"); return 0;} printf("%g%c%g=%g
",a,op,b,c); return 0;}

为了争点分,给你作一个
在窗体三添加二个textbox,一个label,4个按钮command1为控件数组,代表运算符号,一个按钮command2为计算按钮
Dim Yunsuan As String '运算序号
Private Sub Command1_Click(Index As Integer)
Yunsuan = Index '取得运算按钮序号
End Sub
Private Sub Command2_Click()
'计算
Select Case Yunsuan
Case 0
Label1.Caption = Val(Text1.Text) + Val(Text2.Text)
Case 1
Label1.Caption = Val(Text1.Text) - Val(Text2.Text)
Case 2
Label1.Caption = Val(Text1.Text) * Val(Text2.Text)
Case 3
If Val(Text2.Text) 0 Then
Label1.Caption = Val(Text1.Text) / Val(Text2.Text)
Else
Label1.Caption = "错误!,除数不能为0!"
End If
case clse
label1="请单击一个运算按钮!"
End Select
End Sub

相关参考:

编程任意输入两个实数a和b,计算下面函数的值,并输出y值。
&b); if (0.0 == b && a < b) { printf("Error!\\n"); return 0; } if (a > b) y = a - b; else if (a < b) y = a \/ b; else y = a * b; printf ("y = %f\\n", y); return 0;}输入示例 -2.0 0.0 3.0 1.0 4.0 4.0 ...

C语言问题 1、编写程序,输入2个数以及加、减、乘、除中的某运算符号,并...
已经测试,运行正常,先输入两个数,然后输入+-*\/中的一个:接着就有结果 include <stdio.h> include <stdlib.h> int main(void){ float a, b;char c;float res;scanf("%f %f\\n", &a, &b);c = getchar();switch (c){ case '+':res = a + b;break;case '-':res = a -...

c语言,有两个整数a,b,由用户输入1,2或3.如输入1,程序就给出ab中大者...
用指向函数的指针作函数参数,书上例题 include<stdio.h> main(){ int max(int,int);int min(int,int);int add(int,int);void fun(int x,int y,int (*p)(int,int));int a=34,b=21,n;printf("输入1or2or3\\n");scanf("%d",&n);if(n==1) fun(a,b,max);else if(n==2)...

从键盘上输入2个实数给变量a和b,并求其差给变量c的程序(用C语言编写...
include <stdio.h> int main (){ double a,b,c;scanf ("%f %f", &a, &b);c=a-b;printf ("a - b = %f", c);}

编写一个程序,从键盘输入2个数a,b,求这两个数的和、差、积与商?
import java.util.*;public class Size{ public static void main(String[] args)throws Exception{ Scanner s= new Scanner(System.in);System.out.print("请输入第一个数:");float a=s.nextFloat();System.out.print("请输入第二个数:");float b=s.nextFloat();System.out.println("两...

任意输入两整数a,b 编写程序求a+|b|的值。C语言题!求解!
include <stdio.h> int main(){ int a,b;scanf("%d%d",&a,&b);printf("%d\\n",b>0?a+b:a-b);return 0;}

c语言输入两个两位数的整数a、b,将a、b合并形成一个整数放在c中。
int num2_1=num2%10;\/*用来保存第二个数num2个位上的数*\/ int result;\/*保存合并后的结果*\/ result=num1_10*1000+num2_1*100+num1_1*10+num2_10;return result;}\/*返回两数合并后的结果,由result返回其值*\/ void main(){ int num1,num2;printf("请输入两个数(中间用逗号隔开):...

写个C语言程序!任意输入两个数,A,B!输出结果是A的B次方!
if(B<0){ while(-B){ result*=A;B++;} result=1\/result;} else if(B>0){ while(B){ result*=A;n--;} } return(result);} 主函数里面调用就可以了,格式是申明:void pow(float A,int B);例如:void main(){ float A;int B;void pow(float A,int B);poe(A,B);} 自己写...

编写一程序,对两个实数实现简单的加减乘除功能(要求用switch语句编写程 ...
include <stdio.h>#include <math.h> void main(){ float a,b;char s;printf("请输入两个数:");scanf("%f%f",&a,&b);printf("请输入规则");scanf("%s",&s);switch(s){ case '+':printf("a+b=:%f",a+b);break;case '-':printf("a-b=:%f",a-b);break;case '*':pri...

c语言 从键盘输入两个实数,要求按代数值由大到小的顺序输出这两个数...
include<stdio.h> int main(){ double a, b;scanf("%lf %lf", &a, &b);if(a>b){ printf("%lf %lf\\r\\n", a, b);}else{ printf("%lf %lf\\r\\n", b,a,);} return 0;}

相关评论

  • 龙盼5590: 用C语言编程:从键盘输入两个实数a和x, 按公式计算并输出y的值:y=a^5+sin(ax)+ln(a+x)+e^ax -
    15210895367: #include<stdio.h> #include<math.h> #define e 2.71828 main() { int a,x; printf("输入2个实数a,x\n"); scanf("%d%d",&a,&x); if(a==0&&x==0)printf("不在ln的定义域内\n"); else printf("a^5+sin(ax)+ln(a+x)+e^ax = %lg\n",pow(a,5)+sin(a*x)+log10(a+x),pow(e,a*x)); return 0; } 主要使用头文件math.h里德函数

  • 龙盼5590: 编写:从键盘上输入2个实数给变量a和b,并求其差给变量c的程序(用C语言编写) 答好加分 -
    15210895367: main() { int a,b,c; scanf("%d %d",a,b); c = a + b; printf("%d + %d = %d /n",a,b,c); }

  • 龙盼5590: c语言程序设计题,1:从键盘上输入两个实数,并求和,把结果输出,结果保留两位小数. -
    15210895367: #include<stdio.h> main() { double a,b; scanf("%lf%lf",&a,&b); printf("%.2lf\n",a+b); }

  • 相关话题

    ap在线精英在线最新简短笑话,好笑的段子,搞笑句子,男女朋友校园冷笑话,搞笑歌词对白台词,夫妻搞笑对话,手机流行笑话,逗人笑的动物经典笑话,最新幽默搞笑图文,好笑的视频分享给朋友
    若有事情,请联系电邮
    © <搞笑吧