三九宝宝网宝宝教育教学论文

急求用C语言编一个多项式的四则运算

03月19日 编辑 39baobao.com

[用C语言编一个迷宫程序]-# --------### # ## # # ### ----# # #-## # # # #### #### # ## ## #-# ## # # # #---# ## # ## # # # # -# ### ## #### ## # # ----# # # ## # # # ## ### ## -# --# --...+阅读

#include

void main()

{

int x,y;

char op;

int d;

printf("第一个整数:");

scanf("%d",&x);

printf("第二个整数:");

scanf("%d",&y);

printf("运算符 (+,—,*,/,%%):");

getchar();

op=getchar();

switch(op)

{

case '+':

printf("%d+%d=%d\n",x,y,x+y);

break;

case '-':

printf("%d-%d=%d\n",x,y,x-y);

break;

case '*':

printf("%d*%d=%d\n",x,y,x*y);

break;

case '/':

if(y==0)

printf("溢出\n");

else

printf("%d/%d=%d\n",x,y,x/y);

break;

case '%':

if(y==0)

printf("溢出\n");

else

printf("%d%%%d=%d\n",x,y,x%y);

break;

default:

printf("输入错误!\n");

break;

}

scanf("%d\n",&d);

}

看看OK不

用c语言编四则运算

用C++写的,用C的话,函数方面很繁琐... 实现不止是整数,小数也可以,但算式中不要有负数,结果中可以有. 2000字不够用,分两部分,前一部分一些全局变量和类的申明: #include #include #include #include #define MAX 100 //定义运算优先顺序数组,1表示优先,0表示相等,-1表示非优先,2表示表达式有误 int com_value[9][9]= { 1,1,-1,-1,-1,1,1,1,2, 1,1,-1,-1,-1,1,1,1,2, 1,1,1,1,-1,-1,1,1,2, 1,1,1,1,-1,-1,1,1,2, 1,1,1,1,2,-1,1,1,2, -1,-1,-1,-1,-1,-1,0,2,2, 1,1,1,1,1,2,1,1,2, -1,-1,-1,-1,-1,-1,2,0,2, 2,2,2,2,2,2,2,2,2 }; //堆栈类模板 template class stack { public: stack(){top=new type[MAX];}; ~stack(){}; type *top; public: void push(type e){*top=e;top++;} type pop(){top--;return*top;} type GetTop(){return *(top-1);} int GetTopValue(type &e) { if(e=='+')return 0;else if(e=='-')return 1; else if(e=='*')return 2;else if(e=='/')return 3; else if(e=='^')return 4;else if(e=='(')return 5; else if(e==')')return 6;else if(e=='=')return 7; else return 8; } int GetTopValue() { type temp=GetTop(); if(temp=='+')return 0;else if(temp=='-')return 1; else if(temp=='*')return 2;else if(temp=='/')return 3; else if(temp=='^')return 4;else if(temp=='(')return 5; else if(temp==')')return 6;else if(temp=='=')return 7; else return 8; } type calculate(char s) { type b=pop(),a=pop(); if(s=='+')return a+b; if(s=='-')return a-b; if(s=='*')return a*b; if(s=='/')return a/b; if(s=='^')return pow(a,b); } };

C语言的四则运算

double cal(double a[],char e[],int j) //定义cal函数,用于判别各运算符号优先级和计算结果 { int i,n,flag=1; //flag用于标识是不是有被除数为0的情况(falg==0),如有则不输出运算结果 for(i=0;i-5) //判别e[i]与e[i+1]的运算级别是否相同 { switch(e[i]) { case 10: a[i+1]=a[i]+a[i+1];break; case 11: a[i+1]=a[i]-a[i+1];break; case 20: a[i+1]=a[i]*a[i+1];break; case 21: { if(a[i+1]==0) { printf("错误,被除数不能为\n");flag=0;} //被除数为时,flag=0 else a[i+1]=a[i]/a[i+1];break; } } for(n=i;i

以下为关联文档:

C语言问题四则运算程序我怀疑你代码的这段有问题: else if(ch == ')') { optr = MathOptr(ch); while(!Stack1Empty(&OptrStack) & Peek1(&OptrStack).stackprecedence >= optr.inputprecedence) //...

用c语言编四则运算用C++写的,用C的话,函数方面很繁琐... 实现不止是整数,小数也可以,但算式中不要有负数,结果中可以有. 2000字不够用,分两部分,前一部分一些全局变量和类的申明: #include #include #...

急求 c语言怎么编求导函数求导数有两种,一种是表达式求导,一种是数值求导。 表达式求导:需要对表达式进行词法分析,然后用常见的求导公式进行演算,求得导函数。在这方面,数学软件matrix,maple做得非常好。...

c语言多项式求导#include#include typedef struct polynode { int conf;/*常数*/ int exp;/*指数*/ struct polynode *next; }polynode; int main() { polynode *p,*q,*h; /*建立多项式*/ int...

急求用汇编语言实现1至100的累加运算写一个子程序 用CX作为入口参数 BX作为出口参数存放结果 mov cx,100 call leijia 如果是累加到1000 mov cx,1000 call leijia 还有就是记的保护现场 leijia proc mov dx,1 m...

易语言编一个随机生成四则运算的软件.版本 2 .程序集 窗口程序集1 .程序集变量 运算符号, 文本型, , "4" .子程序 __启动窗口_创建完毕 运算符号 = { “+”, “-”, “*”, “÷” } 时钟1.时钟周期 = 1000 标签2.标题...

求用C语言编一个猜数字游戏#include <stdio.h> #include <stdlib.h> int main() { int a,b,math,c; char f; printf("开始游戏?y/n"); scanf("%c",&f); switch(f){ case('y'): printf("请输入数字。"); b=1+rand()...

C语言的四则运算double cal(double a[],char e[],int j) //定义cal函数,用于判别各运算符号优先级和计算结果 { int i,n,flag=1; //flag用于标识是不是有被除数为0的情况(falg==0),如有则不输出...

C语言急求编写一个指数运算的函数参数double int#include<stdio.h> double math(double a,int i) { int dd=1; for(int k=0;k<i;k++) { dd*=a; } return dd; } void main() { double m; int n; scanf("%lf%d",&m,&n); double...

推荐阅读
图文推荐