本文介绍了printf头痛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! #include< stdio.h> int main(无效) { unsigned long gcd(unsigned long m,unsigned long n); unsigned long m; unsigned long n; unsigned long t; ​​ m = 2520; n = 154; t = gcd(m,n); printf("%f是gcd \ n",t); 返回0; } 无符号长gcd(无符号长m,无符号长n) { if(m< n) { unsigned long temp = m; m = n; n = temp; } if(n> 0) { unsigned long r; do { r = m%n; m = n; n = r? r:n; } while(r> 0); } 返回n; } / *结束代码* / 这个编译和行为除了printf。我已经扫过了 K& R打印标志到%%并且我猜对了。 Joe 解决方案 您正在使用%f(float)来打印无符号长整数。试试%d。 - Ian Collins。 您正在使用%f(float)来打印无符号长整数。试试%d。 或者甚至%ld :-) - Al Balmer 亚利桑那州太阳城 您正在使用%f(float)来打印无符号长整数。试试%d。 为什么?那也错了。无论是演员还是使用%ul。 Brian #include <stdio.h>int main(void){unsigned long gcd(unsigned long m, unsigned long n);unsigned long m;unsigned long n;unsigned long t;m = 2520;n = 154;t = gcd(m, n);printf("%f is gcd\n", t);return 0;}unsigned long gcd(unsigned long m, unsigned long n){if(m < n){unsigned long temp = m;m = n;n = temp;}if(n > 0){unsigned long r;do{r = m % n;m = n;n = r ? r : n;} while(r > 0);}return n;}/* end code */This compiles and behaves with the exception of the printf. I''ve scouredK&R print flags to %% and am out of guesses. Joe 解决方案You are using %f (float) to print an unsigned long. Try %d.--Ian Collins.You are using %f (float) to print an unsigned long. Try %d.Or maybe even %ld :-)--Al BalmerSun City, AZ You are using %f (float) to print an unsigned long. Try %d.Why? That''s also wrong. Either cast or use %ul.Brian 这篇关于printf头痛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-01 09:33