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

Python010

用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())}}这个是比较简单的。。。但是有点难理解。。。不过运行绝对正确。。还支持括号。。。但是在这个程序里面我加没有出错处理。。。另一种方法是用栈写。。。这个好理解。。但是麻烦。。。

请自行查看我前面写得GO语言开发环境和GO语言IDE编辑器的经验文章

我们先写一段GO代码

很简单就是打印输出一个hello world!

保存为print.go文件

然后再CMD下一路cd到print.go目录下来

在cmd下运行 go run print.go就可以运行go程序了

看看运行结果

GO程序的代码是可以直接编译成exe文件的

在print.go目录下运行 go build print.go即可把go程序编译成exe文件

完成之后看看exe文件是否存在

最好我们要看看运行exe的效果

case QImage::Format_RGB32:

case QImage::Format_ARGB32:

case QImage::Format_ARGB32_Premultiplied:

for(int i = 0i <heighti ++)

{

const QRgb *pSrc = (QRgb *)image.constScanLine(i)

uchar *pDest = (uchar *)ret.scanLine(i)

for( int j = 0j <widthj ++)

{

pDest[j] = qGray(pSrc[j])

}

}

break

}

return ret

}