用go语言写一个简单的加减乘除的代码,急求 在线等

Python014

用go语言写一个简单的加减乘除的代码,急求 在线等,第1张

/*Note:YourchoiceisCIDE*/#include"stdio.h"#include"stdlib.h"#include"ctype.h"intn=0charrecord[20]floatproduct()floatchange()floatmuli(){floatsummsumm=product()while(record[n]=='-'||record[n]=='+'){switch(record[n]){case'+':n++summ+=product()breakcase'-':n++summ-=product()break}}returnsumm}floatproduct(){floatsumpsump=change()while(record[n]=='*'||record[n]=='/'){switch(record[n]){case'*':n++sump*=change()breakcase'/':n++sump/=change()break}}returnsump}floatchange(){floatsumccharrec[20],i=0if(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)}returnsumc}voidmain(){while(1){n=0scanf("%s",record)printf("%s=%g\n",record,muli())}}这个是比较简单的。。。但是有点难理解。。。不过运行绝对正确。。还支持括号。。。但是在这个程序里面我加没有出错处理。。。另一种方法是用栈写。。。这个好理解。。但是麻烦。。。

golang原生数据类型:按长度:int8(-128-127)、int16、int32、int64。

布尔型:布尔型的值只可以是常量true或者false。一个简单的例子:varbbool=true。

数字类型:整型int和浮点型float32、float64,Go语言支持整型和浮点型数字,并且支持复数,其中位的运算采用补码。

字符串类型:字符串就是一串固定长度的字符连接起来的字符序列。Go的字符串是由单个字节连接起来的。Go语言的字符串的字节使用UTF-8编码标识Unicode文本。

派生类型:包括:(a)指针类型(Pointer)(b)数组类型?结构化类型(struct)(d)Channel类型(e)函数类型(f)切片类型(g)接口类型(interface)(h)Map类型。