当前位置:三九宝宝网 → 宝宝教育 → 教学论文 → 正文

四则运算 c语言编程

更新:12-22 整理:39baobao.com
字体:

[linux环境下用c语言编程]1 2 3 4 5 6 7 8 9 10 11 12 13 #include <stdio.h> intmain() { intsum=0; inti; for(i=50;i<=100;i++) sum += i; printf("my name is zhang san, sum=%d\n", sum); } 编译:g...+阅读

#include "stdio.h" #include "stdlib.h" #include "ctype.h" int n=0; char record[20]; float product(); float change(); float muli() { float summ; summ=product(); while(record[n]=='-'||record[n]=='+') { switch(record[n]) { case '+':n++;summ+=product();break; case '-':n++;summ-=product();break; } } return summ; } float product() { float sump; sump=change(); while(record[n]=='*'||record[n]=='/') { switch(record[n]) { case '*':n++;sump*=change();break; case '/':n++;sump/=change();break; } } return sump; } float change() { float sumc; char rec[20],i=0; if(record[n]=='(') { n++; sumc=muli(); } if(record[n]==')') n++; while(isdigit(record[n])||record[n]=='.') { while(isdigit(record[n])||record[n]=='.') rec[i++]=record[n++]; rec[i]='\0'; sumc=atof(rec); } return sumc; } void main() { while(1) { n=0; scanf("%s",record); printf("%s=%g\n",record,muli()); } }

本文地址:https://www.39baobao.com/show/29_13328.html

以上内容来自互联网,请自行判断内容的正确性。若本站收录的信息无意侵犯了贵司版权,请联系我们,我们会及时处理和回复,谢谢.

以下为关联文档:

c语言编程题数组#include <stdio.h> int main() { char str[100]={0}; char ch; int i=0; printf("输入字符串!\n"); scanf("%c",&ch); while(ch!='\n') { if (ch<='z'&&ch>='a') { if(ch=='z')ch=...

求几道简单C语言编程题关于数组的感谢 !第一题: #include "stdio.h" void main() {int a[10]; int i,max; for(i=0;i<10;++i) scanf("%d,",&a[i]); max=a[0]; for(i=1;i<10;i++) { if(max<a[i]); max=a[i]; } printf("最...

C语言四则运算程序高手帮帮忙#include<stdio.h> #include<stdlib.h> #include<time.h> #include<string.h> int scan() { char s[100]; int i,t,z=0; do { z=0; gets(s); for(i=0;s[i]!='\0';i++) if(s[...

C语言四则运算程序高手帮帮忙!#include #include #include #include int scan() { char s[100]; int i,t,z=0; do { z=0; gets(s); for(i=0;s[i]!='\0';i++) if(s[i]'9') break; if(i>=strlen(s)) for(t=...

C语言问题四则运算程序我怀疑你代码的这段有问题: else if(ch == ')') { optr = MathOptr(ch); while(!Stack1Empty(&OptrStack) & Peek1(&OptrStack).stackprecedence >= optr.inputprecedence) //...