|
|
本帖最后由 Jackxwb 于 2016-3-5 01:44 编辑
变量上已经用了long类型了,从数值上看也没有超出范围。
原程序地址:http://www.cnblogs.com/PegasusWang/archive/2013/03/17/2965189.html
关于printf命令用了中文社区 奈何col 的程序
地址:http://www.arduino.cn/thread-8366-1-1.html
移植版(本人copy后略微修改过)
- int a = 10000, b, c = 1000, e, g, ls, ls2, cs;
- long d, f[1001];
- int serial_putc( char c, struct __file * )
- {
- Serial.write( c );
- return c;
- }
- void printf_begin(void)
- {
- fdevopen( &serial_putc, 0 );
- }
- void setup() {
- // put your setup code here, to run once:
- int i;
- Serial.begin(9600);
- printf_begin();
- Serial.println("pi =");
- for (i = 0; i < c; i++)
- f[i] = a / 5;
- while (c != 0)
- {
- d = 0;
- g = c * 2;
- b = c;
- while (1)
- {
- d = d + f[b] * a;
- g = g - 1;
- f[b] = d % g;
- d = d / g;
- g = g - 1;
- b = b - 1;
- if (b == 0) break;
- d = d * b;
- }
- c = c - 14;
- cs++;
- printf("(%.4d)%d", e + d / a, cs);//此次加括号仅为了好看。cs本为循环次数
- if (e + d / a == 0) break;
- e = d % a;
- }
- Serial.println("");
- Serial.println("run:" + ls);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|