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

谁有c语言的后缀表达式求值

02月23日 编辑 39baobao.com

[在c语言中:编程出输出九九乘法表的表达式]1 2 3 4 5 6 7 8 #include<stdio.h> voidmain(void) { inti,j; for(i=1;i<=9;i++) 1653for(j=1;j<=i;j++) printf("%1d*%1d=%-3d%c",j,i,j*i,j<i?';':'\n'); }...+阅读

#include using namespace std;#include #include #define add 43#define subs 45#define mult 42#define div 47#define maxsize 100 typedef struct { int stkdata[maxsize]; int top; } stkzone; typedef stkzone *stk; typedef enum {true=1,false=0} boo; typedef enum {ok,error} status; stkzone expstkzone; stk expstk; stk initstk(stkzone *stack_zone) { stack_zone->top=-1; return stack_zone; } status push(int*term,stk pstk) { if(pstk->top==maxsize-1) return error; pstk->stkdata[++pstk->top]=*term; return ok; }/*push*/ bool emptystk(stk pstk) { return(pstk->top==-1); } status pop(int *pdata,stk pstk) { if(emptystk(pstk)) return error; else { *pdata=pstk->stkdata[pstk->top]; (pstk->top)--; return ok; } } void synerror() { printf("\n 表达式语法错误!\n"); exit(0); } int eval(int a1,int a2,char tag) { switch(tag) { case add: return(a1+a2); case subs: return(a1-a2); case mult: return(a1*a2); case div: return(a1/a2); } } int main() { char c; int opd1,opd2,temp,c1; expstk=initstk(&expstkzone); opd1 = 1; opd2 = 2; push(&opd1,expstk); push(&opd2,expstk); printf("\n后缀表达式:"); while((c=getchar())!='/n') { if(c==' ')continue; if((c>47)&(c { c1=c-48; if(push(&c1,expstk)==error) { printf("\表达式太长\n"); exit(0); } } else if((c==add)||(c==subs)||(c==mult)||(c==div)) { if(pop(&opd1,expstk)==error) synerror(); if(pop(&opd2,expstk)==error) synerror(); temp=eval(opd1,opd2,c); push(&temp,expstk); } else { // 你输入的c是多少,根本就不对 printf("c = [%c], c=%0x\n",c,c); synerror(); } }/*while*/ if(pop(&temp,expstk)==error) synerror(); if(!(emptystk(expstk))) synerror(); printf("=%-3d\n",temp); return 0; }/*main_end*/// 执行程序看看,你输入的c值是多少,重新设计一下吧

以下为关联文档:

java程序部分求值描述语言及应用框架Java语言是面向对象的程序设计语言,Java程序的基本组成单元是类,类体中又可包括属性与方法两部分。而每一个应用程序都必须包含一个main()方法,含有main()方法的类称之为主类。 J...

任意输入一个逻辑表达式输出它的真值表要用c语言写的/*本程序支持任意输入的逻辑表达式,可以进行与或非和蕴涵的运算,表达式中可带括号.bintree.h和stack.cpp为二叉树和栈的定义及实现*/ #include#include#define MAXNUM 100 //...

谁有C语言课程程序设计实验报告??实 验 报 告 一 课 程 C语言程序设计 实验项目 C程序设计初步 成 绩 专业班级 学 号 指导教师 张耀文 姓 名 序 号 实验日期 一【实验目的】 1. 了解使用VC++6.0的开发环境;...

如何在C语言中使用正则表达式看到大家讨论这方面的东西,作点贡献聊表各位高手对这个版快的无私奉献 :oops: 如果用户熟悉Linux下的sed、awk、grep或vi,那么对正则表达式这一概念肯定不会陌生。由于它可以极...

谁有C语言编写的病毒源代码一个c病毒源代码#include#include#include#include#include#pragma comment(lib,"shlwapi.lib")#define TIMER 1//计时器//functionLRESULT CALLBACK WndProc(HWND, UINT, WPA...

C语言的运算符和表达式有哪些运算符的种类C语言的运算符可分为以下几类: 1.算术运算符 用于各类数值运算。包括加(+)、减(-)、乘(*)、除(/)、求余(或称模运算,%)、自增(++)、自减(--)共七种。 2.关系运算符 用于比较运算...

C语言判断给定表达式的括号是否匹配#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { char c; int i=0,n; int output[100]; int lefts=0,leftm=0,leftb=0; int rights=0,rightm=0...

谁有推箱子的C语言游戏代码#include #include #include #include #include /* 定义二维数组ghouse来记录屏幕上各点的状态, 其中:0表示什么都没有,'b'表示箱子,'w'表示墙壁,'m'表示目的地,'i'表示箱子在目的...

c语言中常量表达式有哪些C语言中的常量与常量表达式与变量 在程序运行过程中,其值不能被改变的量,称为常量。 整型常量:1,0,-1 实型常量:8.2,-3.55 字符常量:'a', 'c'。 常量一般从其字面形式即可判断。...

推荐阅读
图文推荐