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.

所以沒有答案,出這種題目的拖出去斬了