四则运算
来源:互联网 发布:程序员需要读的书 编辑:程序博客网 时间:2024/04/29 08:33
/* HELLO.C -- Hello, world */
#include "stdio.h"
#include "conio.h"
#if 0
int calculate(int statis[],int prio[],int cnt)
{
int i;
for(i=0;i<=cnt;i++)
printf(" statis[%d]=%d\n", i,statis[i]);
}
main()
{
int i[100]={11,12,23,34,45};
int j[100]={1,2,3,4} ;
int k = 4;
calculate(i,j,k);
printf("Hello, world\n");
getch();
}
#include<stdio.h>
#endif
char *s;
int term();
int factor();
int expression()
{
int t;
t = term();
for(;;)
if(*s=='+') { s++; t = t + term(); }
else if(*s=='-') { s++; t = t - term(); }
else break;
return t;
}
int term()
{
int f;
f = factor();
for(;;)
if(*s=='*') { s++; f = f * factor(); }
else if(*s=='/') { s++; f = f / factor(); }
else break;
return f;
}
int factor()
{
int f;
if(*s=='(') {
s++;
f = expression();
if(*s==')') s++;
return f;
}
f=0;
while('0'<=*s && *s<='9') {
f=f*10+(*s-'0');
s++;
}
return f;
}
void main()
{
char *test ;
printf("pls put the biaodashi\n");
scanf("%s",test);
memcpy(s,test,strlen(test));
printf("%d\n",expression());
getch();
}
#include "stdio.h"
#include "conio.h"
#if 0
int calculate(int statis[],int prio[],int cnt)
{
int i;
for(i=0;i<=cnt;i++)
printf(" statis[%d]=%d\n", i,statis[i]);
}
main()
{
int i[100]={11,12,23,34,45};
int j[100]={1,2,3,4} ;
int k = 4;
calculate(i,j,k);
printf("Hello, world\n");
getch();
}
#include<stdio.h>
#endif
char *s;
int term();
int factor();
int expression()
{
int t;
t = term();
for(;;)
if(*s=='+') { s++; t = t + term(); }
else if(*s=='-') { s++; t = t - term(); }
else break;
return t;
}
int term()
{
int f;
f = factor();
for(;;)
if(*s=='*') { s++; f = f * factor(); }
else if(*s=='/') { s++; f = f / factor(); }
else break;
return f;
}
int factor()
{
int f;
if(*s=='(') {
s++;
f = expression();
if(*s==')') s++;
return f;
}
f=0;
while('0'<=*s && *s<='9') {
f=f*10+(*s-'0');
s++;
}
return f;
}
void main()
{
char *test ;
printf("pls put the biaodashi\n");
scanf("%s",test);
memcpy(s,test,strlen(test));
printf("%d\n",expression());
getch();
}
0 0
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- 四则运算
- A + B Problem (X)
- tp 函数目录
- jetty-runner-*.jar 运行war小例子
- zoj2000 Palindrome Numbers
- 有序单链表转BST树+时间复杂度要求O(n)
- 四则运算
- Lua_Math标准库
- Stanford CoreNLP使用
- HDU 2217 Visit 枚举求解
- p52第二单元22题
- P54 第49题 求和
- Lua教程(2):C++和Lua相互传递数据
- 第一篇
- tp 单字母函数详解