prss.net
当前位置:首页 >> C语言 用iF ElsE iF写一个简单的四则运算的计算器... >>

C语言 用iF ElsE iF写一个简单的四则运算的计算器...

#includeint main(){char ch;int a,b,c;printf("")scanf("%d%c%d",&a,&ch,&b);if(ch=='+'){c=a+b;}else if(ch=='-'){c=a-b;}else if(ch=='*'){c=a*b;}else if(ch=='/'){c=a/b;}printf("%d%c%d=%d",a,ch,b,c);return 0;}不知可否,虽然else加不加...

其实还可以加个循环输入的,不过怕你输入格式错误,没加了。。。#include #include int main() { double a,b; char c; scanf("%lf%c%lf",&a,&c,&b); switch(c) { case'+':printf("=%g",a+b);break; case'-':printf("=%g",a-b);break; case'*':pr...

#include int main() {int a,b,c,err; char op; do {scanf("%d%c%d",&a,&op,&b); err=0; if(a==0&&b==0)break; if(op=='+')c=a+b; if(op=='-')c=a-b; if(op=='*')c=a*b; if(op=='/') if(b)c=a/b;else err=1; if(op=='%') if(b)c=a%b;else err=1;...

#includevoidjs(float *i,int j,char c){ float m; scanf("%f",&m); if(c=='*') i[j]=i[j]*m; else i[j]=i[j]/m;}void js2(float *i, char *c, int j, int k){ int l = 0; for (int o=0; o

代码如下:#include void main() { int a,b,sum,flag=0; char fh; //用来记录用户输入的运算符 scanf("%d %c %d =",&a,&fh,&b); //按照这个格式输入运算符例如输入 “1 + 1 =”然后按回车 switch(fh) { case '+':sum=a+b;break; case '-':sum=a-b;...

我都替你写好了,不只是两个数,几个数都行。 支持的数学函数一大堆,pi, e, torad, sin, cos, tan, sinh, cosh, tanh,arcsin, arccos, arctan, arcsinh, arccosh, arctanh,sqrt, abs, lg, ln, exp, gamma, rand, round, int, ceil, floor"方...

#include int main() { double a, b; char op; scanf ("%lf", &a); while (scanf ("%c", &op) && op != '='){ scanf ("%lf", &b); if (op == '+'){ a = a+b; } else if (op == '-'){ a = a-b; } else if (op == '*'){ a = a*b; } else if (op ==...

#include#include"stdlib.h"#define N 10void fun(){ int a,b,t; char c; scanf("%d",&a); scanf(" %c",&c); scanf("%d",&b); if(c=='+'||c=='-'||c=='*'||c=='/'||c=='%') { if(c=='+') t=a+b; if(c=='-') t=a-b; if(c=='*') t=a*b; if(c=='%')...

#include #include #include #include int main() { int type; int left, right; float result; srand(unsigned(time(NULL))); while(1) { type = rand() % 4; left = rand() % 10; right = rand() % 10; switch(type) { case 0: printf("%d + %...

#include //函数,读数操作数 int getNextNum() { int ret; scanf("%d",&ret); return ret; } //函数,读运算符 char getOpt() { return getchar(); } //函数,计算 int caculate(int op1 , int op2 ,char opt) { if(opt=='+')return op1+op2; i...

网站首页 | 网站地图
All rights reserved Powered by www.prss.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com