ucalculateec语言(ucl argue语言)

今天给各位分享ucalculateec语言的知识,其中也会对ucl argue语言进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

1、c语言计数器2、c语言,权植,编写程序段3、求一个迷你计算器的C语言程序(需要注释),拜托在线的好友们4、Calculate a+b 用C语言

c语言计数器

#include stdlib.h

#include math.h

#include graphics.h

#include stdio.h

#include process.h

#define EXCAPE 27

#define ENTER 13

main(){

int press,i,x,y,x1,y1,ch_z=0;

int dian=0;

char ch=’0′; /*input + – * / */

char emp[80],sum[80],*e,*s;

double yuan=0.000000000000;

void init(void);

void clear_z(char *u);

double strtoflt(char *p);

int getkey();

int gd=DETECT, gm;

initgraph(gd, gm, “”);

e=emp;

s=sum;

init();

x = (getmaxx() / 2) – 120;

y = (getmaxy() / 2) – 150;

x1 = (getmaxx() / 2) + 120;

y1 = (getmaxy() / 2) + 150;

while(1){

press = getkey();

switch(press){

case EXCAPE:

exit(0);

case 47:

bar (x + 10, y + 80 + 10, x + 60 – 10, y + 80 + 60 – 10);

delay(8000);

init();

if (ch!=’0′){

switch(ch){

case ‘/’:

if (strtoflt(emp)==0.0){

ch=’0′;

ch_z=0;

dian=0;

emp[0]=’\0′;

sum[0]=’\0′;

e=emp;

s=sum;

outtextxy(x+30,y+40,”error!!!!!”);

break;

}

yuan = strtoflt(sum) / strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

break;

case ‘*’:

yuan = strtoflt(sum) * strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

break;

case ‘+’:

yuan = strtoflt(sum) + strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

break;

case ‘-‘:

if (strtoflt(sum)=strtoflt(emp)){

yuan = strtoflt(sum) – strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

}

else{

yuan=strtoflt(emp)-strtoflt(sum);

sprintf(sum,”-%0.10f”,yuan);

}

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

}

}

else{

if (ch_z==0){

outtextxy(x+30,y+40,emp);

stpcpy(sum,emp);

}

else{

outtextxy(x+30,y+40,sum);

}

}

ch=’/’;

ch_z=0;

emp[0]=’\0′;

e=emp;

dian=0;

break;

case 42:

bar (x + 60 + 10, y + 80 + 10, x + 60 * 2 – 10, y + 80 + 60 – 10);

delay(8000);

init();

if (ch!=’0′){

switch(ch){

case ‘/’:

yuan = strtoflt(sum) / strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

case ‘*’:

yuan = strtoflt(sum) * strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

case ‘+’:

yuan = strtoflt(sum) + strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

case ‘-‘:

if (strtoflt(sum)=strtoflt(emp)){

yuan = strtoflt(sum) – strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

}

else{

yuan=strtoflt(emp)-strtoflt(sum);

sprintf(sum,”-%0.10f”,yuan);

}

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

}

}

else{

if (ch_z==0){

outtextxy(x+30,y+40,emp);

stpcpy(sum,emp);

e=emp;

}

else

outtextxy(x+30,y+40,sum);

}

ch=’*’;

ch_z=0;

dian=0;

break;

case 45:

bar (x + 60 * 2 + 10, y + 80 + 10, x + 60 * 3 – 10, y + 80 + 60 – 10);

delay(8000);

init();

if (ch!=’0′){

switch(ch){

case ‘/’:

yuan = strtoflt(sum) / strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

case ‘*’:

yuan = strtoflt(sum) * strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

case ‘+’:

yuan = strtoflt(sum) + strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

case ‘-‘:

if (strtoflt(sum)=strtoflt(emp)){

yuan = strtoflt(sum) – strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

}

else{

yuan=strtoflt(emp)-strtoflt(sum);

sprintf(sum,”-%0.10f”,yuan);

}

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

}

}

else{

if (ch_z==0){

outtextxy(x+30,y+40,emp);

stpcpy(sum,emp);

e=emp;

}

else

outtextxy(x+30,y+40,sum);

}

ch=’-‘;

ch_z=0;

dian=0;

break;

case 43:

bar (x + 60 * 3 + 10, y + 80 + 10, x + 60 * 4 – 10, y + 80 + 60 – 10);

delay(8000);

init();

if (ch!=’0′){

switch(ch){

case ‘/’:

yuan = strtoflt(sum) / strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

case ‘*’:

yuan = strtoflt(sum) * strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

case ‘+’:

yuan = strtoflt(sum) + strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

case ‘-‘:

if (strtoflt(sum)=strtoflt(emp)){

yuan = strtoflt(sum) – strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

}

else{

yuan=strtoflt(emp)-strtoflt(sum);

sprintf(sum,”-%0.10f”,yuan);

}

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

}

}

else{

if (ch_z==0){

outtextxy(x+30,y+40,emp);

stpcpy(sum,emp);

e=emp;

}

else

outtextxy(x+30,y+40,sum);

}

ch=’+’;

ch_z=0;

dian=0;

break;

case 49:

bar (x + 10, y + 80 + 53 + 10, x + 60 – 10, y + 80 + 53 * 2 – 4);

delay(8000);

init();

for (i=0;i=79;i++){

if (emp[i]==’\0′)

break;

}

if (ch_z==0){

*e=’1′;e++;*e=’\0′;

outtextxy(x+30,y+40,emp);

}

else{

outtextxy(x+30,y+40,sum);

}

break;

case 50:

bar (x + 60 + 10, y + 80 + 53 + 10, x + 60 * 2 – 10, y + 80 + 53 * 2 – 4);

delay(8000);

init();

for (i=0;i=79;i++){

if (emp[i]==’\0′)

break;

}

if (ch_z==0){

*e=’2′;e++;*e=’\0′;

outtextxy(x+30,y+40,emp);

}

else{

outtextxy(x+30,y+40,sum);

}

break;

case 51:

bar (x + 60 * 2 + 10, y + 80 + 53 + 10, x + 60 * 3 – 10, y + 80 + 53 * 2 – 4);

delay(8000);

init();

for (i=0;i=79;i++){

if (emp[i]==’\0′)

break;

}

if (ch_z==0){

*e=’3′;e++;*e=’\0′;

outtextxy(x+30,y+40,emp);

}

else{

outtextxy(x+30,y+40,sum);

}

break;

case ENTER:

bar (x + 60 * 3 + 10, y + 80 + 53 + 10, x + 60 * 4 – 10, y + 80 + 53 * 2 – 4);

delay(8000);

init();

if (ch!=’0′){

switch(ch){

case ‘/’:

yuan = strtoflt(sum) / strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

case ‘*’:

yuan = strtoflt(sum) * strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

case ‘+’:

yuan = strtoflt(sum) + strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

case ‘-‘:

if (strtoflt(sum)=strtoflt(emp)){

yuan = strtoflt(sum) – strtoflt(emp);

sprintf(sum,”%0.10f”,yuan);

}

else{

yuan=strtoflt(emp)-strtoflt(sum);

sprintf(sum,”-%0.10f”,yuan);

}

clear_z(sum);

outtextxy(x+30,y+40,sum);

emp[0]=’\0′;

e=emp;

break;

}

}

else{

if (ch_z==0){

outtextxy(x+30,y+40,emp);

stpcpy(sum,emp);

e=emp;

}

else{

outtextxy(x+30,y+40,sum);

}

}

ch=’0′;

ch_z=1;

dian=0;

break;

case 52:

bar (x + 10, y + 80 + 53 * 2 + 10, x + 60 – 10, y + 80 + 53 * 3 – 4);

delay(8000);

init();

if (ch_z==0){

*e=’4′;e++;*e=’\0′;

outtextxy(x+30,y+40,emp);

}

else{

outtextxy(x+30,y+40,sum);

}

break;

case 53:

bar (x + 60 + 10, y + 80 + 53 * 2 + 10, x + 60 * 2 – 10, y + 80 + 53 * 3 – 4);

delay(8000);

init();

if (ch_z==0){

*e=’5′;e++;*e=’\0′;

outtextxy(x+30,y+40,emp);

}

else{

outtextxy(x+30,y+40,sum);

}

break;

case 54:

bar (x + 60 * 2 +10, y + 80 + 53 * 2 + 10, x + 60 * 3 – 10, y + 80 + 53 * 3 – 4);

delay(8000);

init();

if (ch_z==0){

*e=’6′;e++;*e=’\0′;

outtextxy(x+30,y+40,emp);

}

else{

outtextxy(x+30,y+40,sum);

}

break;

case 46:

bar (x + 60 * 3 + 10, y + 80 + 53 * 2 + 10, x + 60 * 4 – 10, y + 80 + 53 * 3 – 4);

delay(8000);

init();

if (dian==0){

if (ch_z==0){

*e=’.’;e++;*e=’\0′;

outtextxy(x+30,y+40,emp);

}

else{

outtextxy(x+30,y+40,sum);

}

}

else{

if (ch_z==0)

outtextxy(x+30,y+40,emp);

else

outtextxy(x+30,y+40,sum);

}

dian=1;

break;

case 55:

bar (x + 10, y + 80 + 53 * 3 + 10, x + 60 – 10, y + 80 + 53 * 4 – 4);

delay(8000);

init();

if (ch_z==0){

*e=’7′;e++;*e=’\0′;

outtextxy(x+30,y+40,emp);

}

else{

outtextxy(x+30,y+40,sum);

}

break;

case 56:

bar (x + 60 + 10, y + 80 + 53 * 3 + 10, x + 60 * 2 -10, y + 80 + 53 * 4 – 4);

delay(8000);

init();

if (ch_z==0){

*e=’8′;e++;*e=’\0′;

outtextxy(x+30,y+40,emp);

}

else{

outtextxy(x+30,y+40,sum);

}

break;

case 57:

bar (x + 60 * 2 + 10, y + 80 + 53 * 3 + 10, x + 60 * 3 – 10, y + 80 + 53 * 4 – 4);

delay(8000);

init();

if (ch_z==0){

*e=’9′;e++;*e=’\0′;

outtextxy(x+30,y+40,emp);

}

else{

outtextxy(x+30,y+40,sum);

}

break;

case 48:

bar (x + 60 * 3 + 10, y + 80 + 53 * 3 + 10, x + 60 * 4 – 10, y + 80 + 53 * 4 – 4);

delay(8000);

init();

if (ch_z==0){

*e=’0′;e++;*e=’\0′;

outtextxy(x+30,y+40,emp);

}

else{

outtextxy(x+30,y+40,sum);

}

break;

case 32:

emp[0]=’\0′;

sum[0]=’\0′;

e=emp;

s=sum;

ch=’0′;

ch_z=0;

dian=0;

init();

break;

case 8:

delay(8000);

for(i=0;i=79;i++){

if (emp[i]==’\0′)

break;

}

if (i==0)

break;

if (i!=79i!=0){

i–;

emp[i]=’\0′;

e=emp[i];

}

init();

outtextxy(x+30,y+40,emp);

break;

}

}

}

/*———————————————————————*/

void init(void){

int x, y, x1, y1, i, j;

char emp;

x = (getmaxx() / 2) – 120;

y = (getmaxy() / 2) – 150;

x1 = (getmaxx() / 2) + 120;

y1 = (getmaxy() / 2) + 150;

cleardevice();

setbkcolor(3);

setfillstyle(1, 15);

setcolor(15);

settextstyle(1,0,1);

rectangle (x, y, x1, y1);

rectangle (x – 7, y – 7, x1 + 7, y1 + 7);

rectangle (x + 10, y + 10, x1 – 10, y + 80 – 10);

line (x, y + 80, x1, y + 80);

y = y + 80;

for (j = 1; j = 4; j++){

x = (getmaxx() / 2) – 120;

for (i = 1; i = 4; i++){

/* bar (x + 10, y + 10, x + 60 – 10, y + 60 – 10);*/

rectangle(x + 10, y + 10, x + 60 – 10, y + 60 – 10);

if (j == 1){

if (i == 1)

outtextxy(x + 20, y + 20, “/”);

if (i == 2)

outtextxy(x + 25, y + 20, “*”);

if (i == 3)

outtextxy(x + 27, y + 20, “-“);

if (i == 4)

outtextxy(x + 25, y + 20, “+”);

}

if (j == 2){

if (i == 1)

outtextxy(x + 25, y + 20, “1”);

if (i == 2)

outtextxy(x + 25, y + 20, “2”);

if (i == 3)

outtextxy(x + 25, y + 20, “3”);

if (i == 4)

outtextxy(x + 25, y + 20, “=”);

}

if (j == 3){

if (i == 1)

outtextxy(x + 25, y + 20, “4”);

if (i == 2)

outtextxy(x + 25, y + 20, “5”);

if (i == 3)

outtextxy(x + 25, y + 20, “6”);

if (i == 4)

outtextxy(x + 25, y + 20, “.”);

}

if (j == 4){

if (i == 1)

outtextxy(x + 25, y + 20, “7”);

if (i == 2)

outtextxy(x + 25, y + 20, “8”);

if (i == 3)

outtextxy(x + 25, y + 20, “9”);

if (i == 4)

outtextxy(x + 25, y + 20, “0”);

}

x = x + 60;

}

y = y + 53;

}

}

/*———————————————————————*/

int getkey(){

char lowbyte;

int press;

while(bioskey(1)==0);

press = bioskey(0);

press = press0xff? press0xff: press8;

return(press);

}

double strtoflt(char *p)

{

double rtl=0.000000000000;

double pnt=0.000000000000;

double t = 10;

int ispoint = 0;

while (*p!=’\0’||*p!=’.’){

if(*p’0’||*p’9′)

break;

rtl*=10;

rtl+=*p-‘0’;

p++;

}

if (*p==’.’){

ispoint=1;

p++;

}

while(ispoint*p!=’\0′){

pnt+=(double)(*p-‘0’)/t;

t*=10;

p++;

}

rtl+=pnt;

return (rtl);

}

/*———————————————————————–*/

void clear_z(char u[]){

int i;

for(i=strlen(u)-1;i=0;i–){

if (u[i]!=’0′)

break;

}

if (u[i]==’.’){

u[i]=’\0′;

}

else{

i++;

u[i]=’\0′;

}

}

c语言,权植,编写程序段

void calculate(char w[][20],int n,int p[]){

/**********Program**********/

int i, j;

for(i = 0; i  n; i++)

for(j = 0; w[i][j]; j++)

p[i] += (w[i][j] – (w[i][j]  ‘Z’ ? ‘a’ : ‘A’)) / 5 + 1;

/**********  End  **********/

}

void sort(int p[],int n,char w[][20]){

/**********Program**********/

int i, j;

for(i = 0; i  n – 1; i++)

for(j = 0; j  n – 1 – i; j++)

if(p[j]  p[j + 1]) {

char t[20];

strcpy(t, w[j]);

strcpy(w[j], w[j + 1]);

strcpy(w[j + 1], t);

int tmp = p[j];

p[j] = p[j + 1];

p[j + 1] = tmp;

}

/**********  End  **********/

}

求一个迷你计算器的C语言程序(需要注释),拜托在线的好友们

/*** 一共包含四个文件 *************

| Symbol.h

| Stack.h

| Expression.h

| Expression.c

**********************************/

// –Expression.c

#include “Expression.h”

extern EXPRESSION_DEBUG;

STATUS EvaluateExpression(float*,char*);

void Usage(char *);

int HandleOptions(int,char **);

int main(int argc,char*argv[ ])

{

char strLine[30]={0};

float fResult=0;

/* handle the program options */

HandleOptions(argc,argv);

fprintf(stderr,”Input cls to clear the screen\n”);

fprintf(stderr,” debug to show stack change\n”);

fprintf(stderr,” nodebug to show no stack change\n”);

fprintf(stderr,” end to exit\n”);

while(TRUE)

{

printf(“Input:\n”);

gets(strLine);

if(!strcmp(strLine,”end”))

break;

if(!strcmp(strLine,”cls”)) {

system(“cls”);

continue;

}

if(!strcmp(strLine,”debug”)){

EXPRESSION_DEBUG=TRUE;

continue;

}

if(!strcmp(strLine,”nodebug”)){

EXPRESSION_DEBUG=FALSE;

continue;

}

EvaluateExpression(fResult,strLine);

printf(“Ans=%f\n”,fResult);

}

return OK;

}

void Usage(char *programName)

{

fprintf(stderr,”%s usage:%s [-d][-h/?]\n”,programName,programName);

fprintf(stderr,”-d Test program, calculate expression and\n”);

fprintf(stderr,” see changes in the stack at the same time.\n”);

exit(OK);

}

/* returns the index of the first argument that is not an option; i.e.

does not start with a dash or a slash

*/

int HandleOptions(int argc,char *argv[])

{

int i,firstnonoption=0;

for (i=1; i argc;i++) {

if (argv[i][0] == ‘/’ || argv[i][0] == ‘-‘) {

switch (argv[i][1]) {

/* An argument -? means help is requested */

case ‘?’:

case ‘h’:

case ‘H’:

Usage(argv[0]);

break;

case ‘d’:

case ‘D’:

EXPRESSION_DEBUG=TRUE;

break;

default:

fprintf(stderr,”unknown option %s\n”,argv[i]);

break;

}

}

else {

firstnonoption = i;

break;

}

}

return firstnonoption;

}

//–Symbol.h

//–symbol.h – definitions/declarations for symbols used by other C Header files

#ifndef SYMBOL_H

#define SYMBOL_H

#define STACK_H

#define TRUE 1

#define OK 1

#define YES 1

#define FALSE 0

#define ERROR 0

#define NO 0

#define OVERFLOW -1

#ifndef NULL

#define NULL 0

#endif

typedef unsigned int UINT;

typedef int STATUS;

typedef int BOOL;

#endif /*SYMBOL_H*/

//–stack.h – definitions/declarations for stack operation

#ifndef STACK_H

#define STACK_H

#include “Symbol.h”

#include malloc.h

#include stdio.h

#include conio.h

#include stdlib.h

#include string.h

#define S_CHAR 1

#define S_SHORT 2

#define S_INT 3

#define S_FLOAT 4

#define S_DOUBLE 5

//– Stack.h

typedef struct tagNode

{

void*pData;

struct tagNode*pNext;

}Node,*PNode;

typedef struct tagStack

{

UINT uType;

/*1 char

*2 short/short int

*3 int

*4 float

*5 double

*/

UINT uLength;

struct tagNode*pFirst;

struct tagNode*pTop;

}Stack,*PStack;

STATUS InitStack(PStack pStack,UINT uType)

{

pStack-uType=uType;

pStack-uLength=0;

pStack-pFirst=pStack-pTop=NULL;

return OK;

}

STATUS ShowStack(PStack pStack)

{

PNode pNode=pStack-pFirst;

while(pNode)

{

switch(pStack-uType)

{

case S_CHAR: // char

printf(“%c “,*(char*)(pNode-pData));break;

case S_FLOAT: // float

printf(“%-4.1f “,*(float*)(pNode-pData));

}

pNode=pNode-pNext;

}

putchar(10);

return OK;

}

STATUS Push(PStack pStack,void*pData)

{

PNode pNode=(PNode)malloc(sizeof(Node));

if(!pNode)

{

printf(“\nmalloc error!\n”);

fflush(stdin);

getch();

exit(ERROR);

}

if(pStack-uType==1)

{

pNode-pData=(char*)malloc(sizeof(char));

*(char*)(pNode-pData)=*(char*)pData;

}

else if(pStack-uType==3)

{

pNode-pData=(int*)malloc(sizeof(int));

pNode-pData=(int*)malloc(sizeof(int));

*(int*)(pNode-pData)=*(int*)pData;

}

else if(pStack-uType==4)

{

pNode-pData=(float*)malloc(sizeof(float));

pNode-pData=(float*)malloc(sizeof(float));

*(float*)(pNode-pData)=*(float*)pData;

}

else if(pStack-uType==5)

{

pNode-pData=(double*)malloc(sizeof(double));

pNode-pData=(double*)malloc(sizeof(double));

*(double*)(pNode-pData)=*(double*)pData;

}

pNode-pNext=NULL;

if(!pStack-pTop)

pStack-pTop=pStack-pFirst=pNode;

else

{

pStack-pTop-pNext=pNode;

pStack-pTop=pNode;

}

pStack-uLength++;

return OK;

}

STATUS Pop(PStack pStack,void*pData)

{

PNode pPre=pStack-pFirst;

if(pStack-pTop!=pStack-pFirst)

while(pPre-pNext!=pStack-pTop)

pPre=pPre-pNext;

else

pPre=NULL;

if(pStack-uType==1)

*(char*)(pData)=*(char*)(pStack-pTop-pData);

else if(pStack-uType==3)

*(int*)(pData)=*(int*)(pStack-pTop-pData);

else if(pStack-uType==4)

*(float*)(pData)=*(float*)(pStack-pTop-pData);

else if(pStack-uType==5)

*(double*)(pData)=*(double*)(pStack-pTop-pData);

free(pStack-pTop-pData);

free(pStack-pTop);

pStack-pTop=pPre;

if(pPre)

pStack-pTop-pNext=NULL;

else

pStack-pFirst=NULL;

pStack-uLength–;

return OK;

}

STATUS GetTop(PStack pStack,void*pData)

{

if(pStack-uType==1)

*(char*)(pData)=*(char*)(pStack-pTop-pData);

else if(pStack-uType==3)

*(int*)(pData)=*(int*)(pStack-pTop-pData);

else if(pStack-uType==4)

*(float*)(pData)=*(float*)(pStack-pTop-pData);

else if(pStack-uType==5)

*(double*)(pData)=*(double*)(pStack-pTop-pData);

return OK;

}

STATUS DestroyStack(PStack pStack)

{

PNode pPre1,pPre2;

pPre1=pPre2=pStack-pFirst;

while(pPre1)

{

pPre1=pPre1-pNext;

free(pPre2-pData);

free(pPre2);

pPre2=pPre1;

}

pStack-pFirst=pStack-pTop=NULL;

pStack-uLength=0;

return OK;

}

#endif /* STACK_H */

//–Expresson.h

#ifndef EXPRESSION_H

#define EXPRESSION_H

#include “Stack.h”

typedef struct tagOptr

{

char cOptr;

UINT uPriority;

}Optr,*POptr;

BOOL EXPRESSION_DEBUG=FALSE;

Optr pOptr[8]={{0,7},{‘)’,1},{‘*’,2},{‘/’,2},{‘+’,3},{‘-‘,3},{‘(‘,4},{‘#’,4}};

STATUS Operate(float*fTemp3,float fTemp1,char theta,float fTemp2)

{

switch(theta)

{

case ‘+’:*fTemp3=fTemp1+fTemp2;break;

case ‘-‘:*fTemp3=fTemp1-fTemp2;break;

case ‘*’:*fTemp3=fTemp1*fTemp2;break;

case ‘/’:

if(fTemp2!=0)

*fTemp3=fTemp1/fTemp2;

else

{

printf(“\n0 can not be divisor!\n\nPress any key to continue…\n”);

fflush(stdin);

getch();

exit(ERROR);

}// else

break;

}

return OK;

}

int Precede(char cOptrTop,char cChar)

{

UINT i,j;

if(cOptrTop==’#’cChar==’#’)

return 0;

if(cChar=='(‘)

return -1;

if(cChar==’)’)

if(cOptrTop=='(‘)

return 0;

else

return 1;

for(i=1;i=pOptr[0].uPriority;i++)

if(pOptr[i].cOptr==cOptrTop)

{

i=pOptr[i].uPriority;

break;

}

for(j=1;j=pOptr[0].uPriority;j++)

if(pOptr[j].cOptr==cChar)

{

j=pOptr[j].uPriority;

break;

}

if(i=j)

return 1;

else

return -1;

return -2;

}

STATUS IsIn(char cChar)

{

if(cChar=’0’cChar=’9’||cChar==’.’)

return YES;

return NO;

}

STATUS Debug(PStack stackOptr,PStack stackOpnd,char*strExpression,int i)

{

// –debug

if(EXPRESSION_DEBUG)

{

printf(“——————————-\n”);

printf(“%s\n”,strExpression);

printf(“Optr:”);

ShowStack(stackOptr);

printf(“Opnd:”);

ShowStack(stackOpnd);

}

return OK;

}

STATUS EvaluateExpression(float*fResult,char*strExpression)

{

char cChar=’#’,cOptrTop=0,theta=0;

float fTemp1,fTemp2,fTemp3,fTemp4;

int i=0,iTemp;

Stack stackOptr,stackOpnd;

InitStack(stackOptr,S_CHAR);

InitStack(stackOpnd,S_FLOAT);

Push(stackOptr,cChar);

GetTop(stackOptr,cOptrTop);

strcat(strExpression,”#”);

if(strExpression[0]==’-‘){

fTemp1=0;

Push(stackOpnd,fTemp1);

}

cChar=strExpression[0];

while(cChar!=’#’||cOptrTop!=’#’)

{

Debug(stackOptr,stackOpnd,strExpression,i);

if(IsIn(cChar))

{

fTemp1=0;

fTemp3=10;

fTemp4=1;

while(IsIn(cChar))

{

if(cChar==’.’){

fTemp3=1;

cChar=strExpression[++i];

continue;

}

fTemp2=(float)(cChar-‘0’);

if(fTemp3==1)

{

iTemp=i;

while(IsIn(strExpression[i])){

fTemp2/=10;

i++;

}

i=iTemp;

}

fTemp1=fTemp1*fTemp3+fTemp2;

cChar=strExpression[++i];

}

Push(stackOpnd,fTemp1);

}

else

{

switch(Precede(cOptrTop,cChar))

{

case -1:Push(stackOptr,cChar);cChar=strExpression[++i];break;

case 0:Pop(stackOptr,cChar);cChar=strExpression[++i];break;

case 1:

Pop(stackOptr,theta);

Pop(stackOpnd,fTemp2);Pop(stackOpnd,fTemp1);

Operate(fTemp3,fTemp1,theta,fTemp2);

Push(stackOpnd,fTemp3);

break;

}// switch

GetTop(stackOptr,cOptrTop);

}// else

}// while

Pop(stackOptr,cChar);

Debug(stackOptr,stackOpnd,strExpression,i);

GetTop(stackOpnd,fResult);

DestroyStack(stackOptr);

DestroyStack(stackOpnd);

return OK;

}// EvaluateExpression

#endif // EXPRESSION_H

Calculate a+b 用C语言

#include stdio.h

int main()

{

int a,b;

scanf(“%d%d”, a, b);

printf(“%d”, a+b);

return 0;

}

希望可以帮到你。

ucalculateec语言(ucl argue语言)

关于ucalculateec语言和ucl argue语言的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

本文来自投稿,不代表【】观点,发布者:【

本文地址: ,如若转载,请注明出处!

举报投诉邮箱:253000106@qq.com

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2024年3月31日 18:08:31
下一篇 2024年3月31日 18:19:44

相关推荐

  • c语言改写模式,c语言实现修改功能

    c语言程序修改? 1、这个程序有4个错误,我都加粗了,第一个是m没有赋初值,第二个是while表达式中的ch=getchar()需要括号括起来,第三个是m=m*10+ch-0中的0也需要用单引号括起来,第四个是第2个while中为m!=0。 2、define容易造成误会,因为不符合一般的编程习惯,false 0, true 1;scanf放在你的那个地方是达…

    2024年5月23日
    3900
  • c语言控制代码的换码序列,c语言交换代码

    求C语言编程大神解答一下下面这个编程代码? k==5,用5去除125余0,所以r=125%5中r为0。由于!0为1,所以执行while循环体:先打印出5(k的值),再n=n/k==125/5=25;由于251则再打印出*号。这一循环结果输出是5*。 下面是我的代码,三个函数分别对应三个问题。 在实现基本要求的前提下,拓展了可以从键盘输入的功能,以下为各题代码…

    2024年5月23日
    5600
  • c语言扫描io脚状态,c语言端口扫描

    求51单片机的上升沿和下降沿C语言检测程序列子,端口就是普通IO口。 上升沿触发是当信号有上升沿时的开关动作,当电位由低变高而触发输出变化的就叫上升沿触发。也就是当测到的信号电位是从低到高也就是上升时就触发,叫做上升沿触发。 单片机怎么计算1s内下降沿的个数的C语言程序或者计算两个下降沿的时间(检测脉冲频率)计算1s内下降沿的个数方法是,一个定时器设置定时1…

    2024年5月23日
    4400
  • c语言mallloc使用的简单介绍

    C语言中使用malloc必须加#includemallo.h? 1、在C语言中使用malloc函数进行动态内存分配。malloc的全称是memory allocation,中文叫动态内存分配。原型:extern void malloc(unsigned int num_bytes);功能:分配长度为num_bytes字节的内存块。 2、你可以看一下C语言那本…

    2024年5月23日
    4400
  • c语言三位小数,C语言三位小数

    怎样用C++语言输出精确到小数点后三位的数? 1、用C++语言输出精确到小数点后三位的数,可以参考下面给出的代码:coutsetiosflags(ios:fixed)setprecision(3)。其中 setiosflags中set是设置的意思。ios是iostream的缩写,即输入输出流。flags是标志的意思。 2、要精确到小数点后若干位,则数据类型为…

    2024年5月23日
    7200
  • c语言21点游戏,二十一点游戏代码c语言

    如何使用C语言编写简单小游戏? 1、数学知识:长方形的面积S=a*b 长方形周长L=2*(a+b)其中a b分别为长方形的宽和高。算法分析:长方形面积及周长均依赖于宽和高,所以先要输入宽高值,然后根据公式计算,输出结果即可。 2、/*也不知道你是什么级别的,我是一个新手,刚接触编程语言,以下是我自己变得一个小程序,在所有c语言的编译器(vc++0、turbo…

    2024年5月23日
    6300
  • c语言当中的null,C语言当中的符号

    C/C++中,NULL和null的区别是什么? nul 和 null要看编译器,不同的编译器有所区别。 所以C或者C++中都使用一个特殊定义NULL表示无效值,其本质就是未定义具体数据类型的0值。 null是是什么都没有的意思。在java中表示空对象。 本意是“空的;元素只有零的”意思。计算机中通常表示空值,无结果,或是空集合。\x0d\x0a在ASCII码…

    2024年5月23日
    4500
  • 包含c语言对txt文件命名的词条

    如何在C语言编程里面修改源文件名字 如果你是在WINDOWS的话,简单了,随便用个编辑器,比如记事本,然后写c源程序,保存到你想要保存的位置。如果你在DOS下,可以用edit,写好以后,按alt键,选择文件菜单,然后保存。 用open打开文件,注意操作模式使用“修改”或者“添加” 用write或者fprintf向文件中写入你的内容。 用close关闭文件。 …

    2024年5月23日
    4800
  • 学c语言编程,学c语言编程用什么软件

    编程开发必须要学C语言吗? 1、要学习。编程开发的学习内容主要包括c语言、python和c+语言。C语言作为一种简单灵活的高级编程语言,它是一个面向过程的语言,一般是作为计算机专业的基础入门语言课程。 2、C语言。对于刚接触编程的人来说,先学习C语言是非常重要的。C语言可以说是是计算机编程语言的鼻祖,其他的编程语言几乎全是由C语言变化衍生出来的。 3、不需要…

    2024年5月23日
    3400
  • c语言用string定义字符串,c语言中用string类型来处理字符串类型

    C++怎样定义定义字符串 1、第一是字符数组来表示字符串。用下面的语句声明:char a[10];C语言中字符数组与字符串的唯一区别是字符串末尾有一个结束符\0,而字符数组不需要。 2、在C中定义字符串有下列几种形式:字符串常量,char数组,char指针 字符串常量 即:位于一对双括号中的任何字符。双引号里的字符加上编译器自动提供的结束标志\0字符,作为 …

    2024年5月23日
    4300

发表回复

登录后才能评论



关注微信