A. c语言表达式求值代码

#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<stdlib.h>
static int gv_a;
typedef struct list //创建队列元素型
{
char str[10];
struct list*pNext;
}LIST;
typedef struct queue //创建队列表型
{
LIST *front;
LIST *rear;
}QUEUE;
typedef struct oprstack //创建运算符栈型
{
char opr[100];
int a;
}OPRSTACK;
typedef struct valstack //创建运算栈型
{
float val[30];
int a;
}VALSTACK;
typedef struct element //创建表达式栈元素型
{
char c;
struct element *pNext;
}ENT;
typedef struct stack //创建表达式栈 型
{
ENT *pTop;
ENT *bottom;
}STACK;
bool calc(char *str,float *result);
float evaluationofexpression(char *str);
int main(void)
{
char str[50];
float result;
printf("请输入要计算的表达式:");
scanf("%s",str);
result = evaluationofexpression(str);
if (gv_a)
return 0;
printf("结果:%f",result);
printf("\n");
return 0;
}

B. 表达式求值是源代码(栈)

#include<stdio.h>
#include<malloc.h>
#include<string.h>
typedef struct Fnode/*符号单链表*/
{
int yxj;
char fh;
struct Fnode *next;
}Fnode;

void F_push(Fnode *h,char c)/*尾插*/
{
Fnode *p;
p=(Fnode*)malloc(sizeof(Fnode));
p->fh=c;
p->next=NULL;
if(c=='+'||c=='-')
p->yxj=1;
else if(c=='*'||c=='/')
p->yxj=2;
else if(c=='('||c==')')
p->yxj=0;
else
{ free(p); return;}
while(h->next!=NULL)
h=h->next;
p->next=h->next;
h->next=p;
}

char F_pop(Fnode *h)/*尾删*/
{
char c;
while(h->next->next!=NULL)
h=h->next;
c=h->next->fh;
free(h->next);
h->next=NULL;
return c;
}
int F_look(Fnode *h)
{
while(h->next!=NULL)
h=h->next;
return h->yxj;
}

/*------------------------------------------------------------*/
typedef struct Snode/*数字单链表*/
{
double data;
struct Snode *next;
}Snode;

void S_push(Snode *h,double c)/*尾插*/
{
Snode *p;
p=(Snode*)malloc(sizeof(Snode));
p->data=c;
p->next=NULL;
while(h->next!=NULL)
h=h->next;
p->next=h->next;
h->next=p;
}

double S_pop(Snode *h)/*尾删*/
{
double i;
while(h->next->next!=NULL)
h=h->next;
i=h->next->data;
free(h->next);
h->next=NULL;
return i;
}
/*-------------------------------------------------------*/

char *change(char *str)/*字符串前加(,后加 )*/
{
char *r;
*(str-1)='(';
str--;
r=str;
strcat(r,")");
return r;
}
/*;-------------------------------------------------*/
double final(char *str,Fnode *fh,Snode *sh)/*计算表达式结果*/
{
double i,temp,emp;
while(*str!='\0')
{
if(*str=='(')
{
F_push(fh,*str);
str++;
continue;
}
else if(*str>='0'&&*str<='9')
{
emp=0;
while(*str>='0'&&*str<='9')
{
emp=emp*10+(*str-'0');
str++;
}
S_push(sh,emp);
continue;
}
else if(*str=='.')
{
i=0.1; str++; emp=0;
if(*str>='0'&&*str<='9')
{
while(*str>='0'&&*str<='9')
{
emp+=(*str-'0')*i;
i*=0.1;
str++;
}
S_push(sh,(S_pop(sh)+emp));
}
}
else if(*str==')')
{
while(F_look(fh)!=0)
{
switch(F_pop(fh))
{
case '+':emp=S_pop(sh);S_push(sh,(S_pop(sh)+emp));break;
case '-':emp=S_pop(sh);S_push(sh,(S_pop(sh)-emp));break;
case '*':emp=S_pop(sh);S_push(sh,(S_pop(sh)*emp));break;
case '/':emp=S_pop(sh);S_push(sh,(S_pop(sh)/emp));break;
default :;
}
}
F_pop(fh);
str++;
continue;
}
else
{
if(*str=='+'||*str=='-')
temp=1;
else
temp=2;
if(temp>F_look(fh))
F_push(fh,*str);
else
{
switch(F_pop(fh))
{
case '+':emp=S_pop(sh);S_push(sh,(S_pop(sh)+emp));break;
case '-':emp=S_pop(sh);S_push(sh,(S_pop(sh)-emp));break;
case '*':emp=S_pop(sh);S_push(sh,(S_pop(sh)*emp));break;
case '/':emp=S_pop(sh);S_push(sh,(S_pop(sh)/emp));break;
default :;
}
F_push(fh,*str);
}
str++;continue;
}
}
return S_pop(sh);
}

main()
{
Fnode *fh;
Snode *sh;
char *str;
fh=(Fnode*)malloc(sizeof(Fnode));
fh->next=NULL;
sh=(Snode*)malloc(sizeof(Snode));
sh->next=NULL;
str=change(gets(str));
printf("%lf",final(str,fh,sh));
getch();
}

C. 求表达式求值的C语言代码

在严蔚敏数据结构书中有关于表达式求值的算法,可以参考下~

D. 表达式求值的C语言源代码

一个用C#编写的简单的数学表达式解析器,实现了C语言里的几乎所有运算符和几乎所有数版学库函数,并且实现了权定义自变量的功能。程序没有运用中缀表达式、后缀表达式和前缀表达式的思想,而只是运用循环的方法从左到右扫描表达式。进入下载网址http://hi..com/%C9%B9%D1%A7%CD%F8/album/item/d6b05d9b9fa707bfc8eaf448.html后,右击软件运行界面的图片,点击“目标另存为...”。将扩展名改为rar,然后可以用Winrar打开。

E. 编译原理 语义分析 算术表达式求值代码

java字符串算术表达式求值:importjava.util.ArrayList;importjava.util.Stack;/****@authoryhh**/publicclassCalculate{/***将字内符串转化容成List*@paramstr*@return*/publicArrayListgetStringList(Stringstr){ArrayListresult=newArrayList();Stringnum="";for(inti=0;igetPostOrder(ArrayListinOrderList){ArrayListresult=newArrayList();Stackstack=newStack();for(inti=0;ipostOrder){Stackstack=newStack();for(inti=0;i

F. C语言编一个实现简单的算术表达式求值的代码。

这个是个简单的学生管理系统,我们学校的程序大作业就是做这个...呵呵,希望能帮到你
#include<stdio.h> /*引用库函数*/
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
typedef struct /*定义结构体数组*/
{
char num[10]; /*学号*/
char name[20]; /*姓名*/
int score; /*成绩*/
}Student;
Student stu[80]; /*结构体数组变量*/
int menu_select() /*菜单函数*/
{
char c;
do{
system("cls"); /*运行前清屏*/
printf("\t\t****Students' Grade Management System****\n"); /*菜单选择*/
printf("\t\t | 1. Input Records |\n");
printf("\t\t | 2. Display All Records |\n");
printf("\t\t | 3. Sort |\n");
printf("\t\t | 4. Insert a Record |\n");
printf("\t\t | 5. Delete a Record |\n");
printf("\t\t | 6. Query |\n");
printf("\t\t | 7. Statistic |\n");
printf("\t\t | 8. Add Records from a Text File|\n");
printf("\t\t | 9. Write to a Text file |\n");
printf("\t\t | 0. Quit |\n");
printf("\t\t*****************************************\n");
printf("\t\t\tGive your Choice(0-9):");
c=getchar(); /*读入选择*/
}while(c<'0'||c>'9');
return(c-'0'); /*返回选择*/
}
int Input(Student stud[],int n) /*输入若干条记录*/
{int i=0;
char sign,x[10]; /*x[10]为清除多余的数据所用*/
while(sign!='n'&&sign!='N') /*判断*/
{ printf("\t\t\tstudent's num:"); /*交互输入*/
scanf("\t\t\t%s",stud[n+i].num);
printf("\t\t\tstudent's name:");
scanf("\t\t\t%s",stud[n+i].name);
printf("\t\t\tstudent's score:");
scanf("\t\t\t%d",&stud[n+i].score);
gets(x); /*清除多余的输入*/
printf("\t\t\tany more records?(Y/N)");
scanf("\t\t\t%c",&sign); /*输入判断*/
i++;
}
return(n+i);
}
void Display(Student stud[],int n) /*显示所有记录*/
{
int i;
printf("\t\t\t-----------------------------------\n"); /*格式头*/
printf("\t\t\tnumber name score\n");
printf("\t\t\t-----------------------------------\n");
for(i=1;i<n+1;i++) /*循环输入*/
{
printf("\t\t\t%-16s%-15s%d\n",stud[i-1].num,stud[i-1].name,stud[i-1].score);
if(i>1&&i%10==0) /*每十个暂停*/
{printf("\t\t\t-----------------------------------\n"); /*格式*/
printf("\t\t\t");
system("pause");
printf("\t\t\t-----------------------------------\n");
}
}
printf("\t\t\t");
system("pause");
}
void Sort_by_num(Student stud[],int n) /*按学号排序*/
{ int i,j,*p,*q,s;
char t[10];
for(i=0;i<n-1;i++) /*冒泡法排序*/
for(j=0;j<n-1-i;j++)
if(strcmp(stud[j].num,stud[j+1].num)>0)
{strcpy(t,stud[j+1].num);
strcpy(stud[j+1].num,stud[j].num);
strcpy(stud[j].num,t);
strcpy(t,stud[j+1].name);
strcpy(stud[j+1].name,stud[j].name);
strcpy(stud[j].name,t);
p=&stud[j+1].score;
q=&stud[j].score;
s=*p;
*p=*q;
*q=s;
}
}
int Insert_a_record(Student stud[],int n) /*插入一条记录*/
{char x[10]; /*清除多余输入所用*/
printf("\t\t\tstudent's num:"); /*交互式输入*/
scanf("\t\t\t%s",stud[n].num);
printf("\t\t\tstudent's name:");
scanf("\t\t\t%s",stud[n].name);
printf("\t\t\tstudent's score:");
scanf("\t\t\t%d",&stud[n].score);
gets(x);
n++;
Sort_by_num(stud,n); /*调用排序函数*/
printf("\t\t\tInsert Successed!\n"); /*返回成功信息*/
return(n);
}
int Delete_a_record(Student stud[],int n) /*按姓名查找,删除一条记录*/
{ char s[20];
int i=0,j;
printf("\t\t\ttell me his(her) name:"); /*交互式问寻*/
scanf("%s",s);
while(strcmp(stud[i].name,s)!=0&&i<n) i++; /*查找判断*/
if(i==n)
{ printf("\t\t\tnot find!\n"); /*返回失败信息*/
return(n);
}
for(j=i;j<n-1;j++) /*删除操作*/
{
strcpy(stud[j].num,stud[j+1].num);
strcpy(stud[j].name,stud[j+1].name);
stud[j].score=stud[j+1].score;
}
printf("\t\t\tDelete Successed!\n"); /*返回成功信息*/
return(n-1);
}
void Query_a_record(Student stud[],int n) /*查找并显示一个记录*/
{ char s[20];
int i=0;
printf("\t\t\tinput his(her) name:"); /*交互式输入*/
scanf("\t\t\t%s",s);
while(strcmp(stud[i].name,s)!=0&&i<n) i++; /*查找判断*/
if(i==n)
{ printf("\t\t\tnot find!\n"); /*输入失败信息*/
return;

}
printf("\t\t\this(her) number:%s\n",stud[i].num); /*输出该学生信息*/
printf("\t\t\this(her) score:%d\n",stud[i].score);
}
void Statistic(Student stud[],int n) /*新增功能,输出统计信息*/
{ int i,j=0,k=0,sum=0;
float aver; /*成绩平均值*/
for(i=0;i<n;i++) /*循环输入判断*/
{
sum+=stud[i].score;
if(stud[j].score>stud[i].score) j=i;
if(stud[k].score<stud[i].score) k=i;
}
aver=1.0*sum/n;
printf("\t\t\tthere are %d records.\n",n); /*总共记录数*/
printf("\t\t\tthe hignest score:\n"); /*最高分*/
printf("\t\t\tnumber:%s name:%s score:%d\n",stud[j].num,stud[j].name,stud[j].score);
printf("\t\t\tthe lowest score:\n"); /*最低分*/
printf("\t\t\tnumber:%s name:%s score:%d\n",stud[k].num,stud[k].name,stud[k].score);
printf("\t\t\tthe average score is %5.2f\n",aver); /*平均分*/
}
int AddfromText(Student stud[],int n) /*从文件中读入数据*/
{ int i=0,num;
FILE *fp; /*定义文件指针*/
char filename[20]; /*定义文件名*/
printf("\t\t\tInput the filename:");
scanf("\t\t\t%s",filename); /*输入文件名*/
if((fp=fopen(filename,"rb"))==NULL) /*打开文件*/
{ printf("\t\t\tcann't open the file\n"); /*打开失败信息*/
printf("\t\t\t");
system("pause");
return(n);
}
fscanf(fp,"%d",&num); /*读入总记录量*/
while(i<num) /*循环读入数据*/
{
fscanf(fp,"%s%s%d",stud[n+i].num,stud[n+i].name,&stud[n+i].score);
i++;
}
n+=num;
fclose(fp); /*关闭文件*/
printf("\t\t\tSuccessed!\n");
printf("\t\t\t");
system("pause");
return(n);
}
void WritetoText(Student stud[],int n) /*将所有记录写入文件*/
{
int i=0;
FILE *fp; /*定义文件指针*/
char filename[20]; /*定义文件名*/
printf("\t\t\tWrite Records to a Text File\n"); /*输入文件名*/
printf("\t\t\tInput the filename:");
scanf("\t\t\t%s",filename);
if((fp=fopen(filename,"w"))==NULL) /*打开文件*/
{
printf("\t\t\tcann't open the file\n");
system("pause");
return;
}
fprintf(fp,"%d\n",n); /*循环写入数据*/
while(i<n)
{
fprintf(fp,"%-16s%-15s%d\n",stud[i].num,stud[i].name,stud[i].score);
i++;
}
fclose(fp); /*关闭文件*/
printf("Successed!\n"); /*返回成功信息*/
}
void main() /*主函数*/
{
int n=0;
for(;;)
{
switch(menu_select()) /*选择判断*/
{
case 1:
printf("\t\t\tInput Records\n"); /*输入若干条记录*/
n=Input(stu,n);
break;
case 2:
printf("\t\t\tDisplay All Records\n"); /*显示所有记录*/
Display(stu,n);
break;
case 3:
printf("\t\t\tSort\n");
Sort_by_num(stu,n); /*按学号排序*/
printf("\t\t\tSort Suceessed!\n");
printf("\t\t\t");
system("pause");
break;
case 4:
printf("\t\t\tInsert a Record\n");
n=Insert_a_record(stu,n); /*插入一条记录*/
printf("\t\t\t");
system("pause");
break;
case 5:
printf("\t\t\tDelete a Record\n");
n=Delete_a_record(stu,n); /*按姓名查找,删除一条记录*/
printf("\t\t\t");
system("pause");
break;
case 6:
printf("\t\t\tQuery\n");
Query_a_record(stu,n); /*查找并显示一个记录*/
printf("\t\t\t");
system("pause");
break;
case 7:
printf("\t\t\tStatistic\n");
Statistic(stu,n); /*新增功能,输出统计信息*/
printf("\t\t\t");
system("pause");
break;
case 8:
printf("\t\t\tAdd Records from a Text File\n");
n=AddfromText(stu,n); /*新增功能,输出统计信息*/
break;
case 9:
printf("\t\t\tWrite to a Text file\n");
WritetoText(stu,n); /*循环写入数据*/
printf("\t\t\t");
system("pause");
break;
case 0:
printf("\t\t\tHave a Good Luck,Bye-bye!\n"); /*结束程序*/
printf("\t\t\t");
system("pause");
exit(0);
}
}
}

G. 在表达式求值中,这段代码是什么意思啊,详细点哦

char p[10];//定义一个长度为10的char字符数组
itoa(n,p,10);//将整型n以10进制转换成字符并保存到p数组中
n=strlen(p);//获取数内组p的长度,并容将长度赋值给n
return n;//最后n作为函数返回值

H. C语言程序求值

if else部分代码添加缩进后应该是下面这个样子
if (a<b)
if(c<d) x=1;// a<b and c<d, x=1
else//c>=d
if (a<c)//c>=d and a<c
if (b<d) x=2;//c>=d and a<c and b<d, x=2
else x=3;//c>=d and a<c and b>=d, x=3
else x=4;//c>=d and a>=c, x=4
else x=5;//a>=b, x=5
根据题目可知内d<c<a<b, 再结合我上面每句的容注释,代入后可知,x=4

希望能帮到你

I. 编写代码求值计算:++4+5/6>=10%2 && 10/5==++5的值

error: invalid lvalue in increment
compilation terminated e to -Wfatal-errors.

所以没有答案,出这种题目的拖出去斩了