本文介绍了概率与C编程。郎。书(ANSI C)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我刚刚购买了C编程语言,由制作C和 的人所以...我有2个不同的编译器,免费编译器,我不知道我是不是/> 键入错误的代码或者如果它对我的编译器有问题,那么你知道吗?你知道吗?它们是免费的编译器:Icc-win32和Bloodshed Dev C ++(也使用C语言)。除了火星之外还有免费的编译器吗? 和gcc-无论如何都无法让它们起作用。谢谢。 继承代码,它有什么问题: #include< stdio.h> main() { int fahr,摄氏度; int lower,upper,step; lower = 0; upper = 300; step = 20; fahr =更低; 而(fahr< = upper){ 摄氏度= 5 *(fahr-32)/ 9; printf( %d \ t%d \ n,fahr,celsius); fahr = fahr + step; } } 解决方案 " Matt Suther" < DN ****** @ hotmail.com>在消息中写道 除了火星,和gcc之外还有免费的编译器,无法让它们工作。谢谢。 继承代码,它有什么问题: 你不会说出了什么问题。您发布的代码应该生成一个带输出的程序。 请记住,测试C程序有三个阶段。首先你需要 来编译它。编译器会抱怨语法错误,它无法找到b + b的标题,而且类似。编译后,你必须与库链接。 这一步通常但不总是由 编译器自动调用。最后,您必须运行您创建的可执行文件。如果您使用的是免费的编译器,通常必须通过将 a shell /命令提示符设置到您创建可执行文件的目录来完成, 并通过输入名称来运行它。 在哪个阶段出现问题? Matt Suther写道: 我刚刚购买了C编程语言,由制作C的人和所以...我有2个不同的编译器,免费编译器,我不知道是否我打错了代码或者我的编译器有问题, 问题是你打字。 [.. 。] 继承代码,它有什么问题: < stdio.h> main() main返回一个int。你应该这样说(并且必须为C99): int main(无效) { int fahr,摄氏度; int lower,upper ,步骤; lower = 0; upper = 300; step = 20; fahr = lower; while(fahr < = upper){摄氏度= 5 *(fahr-32)/ 9; ^^^^^^^^^^^^^^^^^ 您的输入错误 该程序比这更糟糕,因为即使您更正了 输入错误后,计算出的值例如211.99999将存储在 摄氏度中为211. printf( %d \ t%d \ n,fahr,celsius); fahr = fahr + step; } main返回一个int ,你应该这样说(虽然C99补充说 没有返回,一个程序现在就好像下面的行是 那里): 返回0; } Martin Ambuhl< ma ***** @ earthlink.net>写道: Matt Suther写道: while(fahr< = upper){ celsius = 5 *(fahr-32)/ 9; ^^^^^^^^^^^^^^^^^ 您的输入错误 对不起,但输入错误?在我的K& R2副本中(从1988年开始),它看起来完全像 ,就像OP复制它一样(并且似乎都没有提到的页/行 在勘误表中我也没有看到任何明显错误的东西)。 问候,Jens - \ Jens Thoms Toerring ___ Je *********** @ physik.fu-berlin.de \ __________________________ http://www.toerring.de I just bought The C Programming Language, by the guy who made C andso...I have 2 different compilers, free ones, and I don''t know if Ityped the code in wrong or if it''s a problem with my compilers, do anyof you know? They were free compilers: Icc-win32 and Bloodshed DevC++(uses C too). Are there and compilers that are free besides mars,and gcc-whatever, can''t get them to work. Thanks. heres the code, is there anything wrong with it: #include <stdio.h> main(){int fahr, celsius;int lower, upper, step; lower = 0;upper = 300;step = 20; fahr = lower;while (fahr <= upper) {celsius = 5 * (fahr-32) / 9;printf("%d\t%d\n", fahr, celsius);fahr = fahr + step;}} 解决方案 "Matt Suther" <dn******@hotmail.com> wrote in message Are there and compilers that are free besides mars, and gcc-whatever, can''t get them to work. Thanks. heres the code, is there anything wrong with it:You don''t say what is going wrong. The code you posted should produce aprogram with output.Remember that there are three stages to testing a C program. First you haveto compile it. The compiler will complain about syntax errors, headers itcan''t find, and similar. Once you compile you have to link with libraries.This step will usually but not always be invoked automatically by thecompiler. Finally you have to run the executable file you have created. Ifyou are using a free compiler, usually this will have to be done by settinga shell/command prompt to the directory in which you created the executable,and running it by typing the name.At which stage do things go wrong?Matt Suther wrote: I just bought The C Programming Language, by the guy who made C and so...I have 2 different compilers, free ones, and I don''t know if I typed the code in wrong or if it''s a problem with my compilers,The problem is your typing.[...] heres the code, is there anything wrong with it: #include <stdio.h> main()main returns an int. You should say so (and must for C99):int main(void) { int fahr, celsius; int lower, upper, step; lower = 0; upper = 300; step = 20; fahr = lower; while (fahr <= upper) { celsius = 5 * (fahr-32) / 9;^^^^^^^^^^^^^^^^^Your typing errorThe program is a bit worse than that, since even after you correct yourtyping error, a computed value of, say, 211.99999 will be stored incelsius as 211. printf("%d\t%d\n", fahr, celsius); fahr = fahr + step; }main returns an int, and you should say so (although C99 added thatwithout the return, a program will now act as though the line below werethere):return 0; }Martin Ambuhl <ma*****@earthlink.net> wrote: Matt Suther wrote: while (fahr <= upper) { celsius = 5 * (fahr-32) / 9; ^^^^^^^^^^^^^^^^^ Your typing error Sorry, but what typo? In my copy of K&R2 (from 1988) it looks exactlylike the OP copied it (and neither seems that page/line to be mentionedin the errata list nor do I see anything obviously wrong with it). Regards, Jens--\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de\__________________________ http://www.toerring.de 这篇关于概率与C编程。郎。书(ANSI C)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 18:56