K& R Ex 1-3 [英] K&R Ex 1-3
问题描述
我正在阅读K& R书并进行练习。目前,我在练习1-3上工作了
。
这就是我所拥有的:
Gio写道:
我''我正在阅读K& R书并进行练习。目前,我在练习1-3上工作了
。
这就是我所拥有的:
展开 | 选择 | Wrap | 行号
Gio< gi ******* @ sbcglobal.netwrites:
我正在阅读K& R书并进行练习。目前,我是在锻炼1-3上工作的b $ b。
< snip>
printf(" F\t\tC\ n");
while(fahr< = upper){
摄氏度=(5.0 / 9.0)*(fahr-32.0);
printf("%4.0f%7.1f \ n",fahr,摄氏度);
fahr = fahr + step;
}
< snip>
现在,这完成了练习。从技术上讲,无论如何。但是,我想要
来制作F和C表示C和C。在
各栏的右侧正确对齐。
我喜欢使用与数字
格式相同的尺寸来做到这一点:
printf("%4s%7s \ n"," F"," C");
它保持一切清晰,你甚至可以连接到可配置的大小
来自宏如果你真的想要(虽然这是一个严重的例子,这个练习中的
矫枉过正)。
-
Ben。
当你在那里时,打开编译器的警告,上面的
< blockquote class =post_quotes>
应该导致一个。
嗯..啊......我正在研究Apple II;编译器我运行这个程序
on在技术上是预先ANSI,但我记住了差异(并且
文档近在咫尺)。我想我可以问一个K& R问题,
虽然。
至于为什么我在Apple IIe上学习C ...我这样做是为了习惯编译器和计算机的局限性。而且因为我很有点坚果。 :)
- Gio
-
现在和一个词(IF博客):
http://giomancer.wordpress.com/
I''m reading the K&R book and doing the exercises. Currently, I''m working
on Exercise 1-3.
Here''s what I have:
Expand|Select|Wrap|Line Numbers解决方案Gio wrote:I''m reading the K&R book and doing the exercises. Currently, I''m working
on Exercise 1-3.
Here''s what I have:
Expand|Select|Wrap|Line Numbers
Gio <gi*******@sbcglobal.netwrites:
I''m reading the K&R book and doing the exercises. Currently, I''m
working on Exercise 1-3.<snip>
printf("F\t\tC\n");
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%4.0f %7.1f\n", fahr, celsius);
fahr = fahr + step;
}<snip>
Now, this completes the exercise. Technically, anyway. However, I want
to make the "F" and "C" align properly above the right side of their
respective columns.I like to do this using the same sizes you have in the numeric
format:
printf("%4s %7s\n", "F", "C");
It keeps everything clear, and you can even wire in a configurable size
from a macro if you really want to (although that is a serious case of
overkill in this exercise).
--
Ben.
While you are there, turn your compiler''s warnings up, the aboveshould have caused one.Well.. ah.. I''m working on an Apple II; the compiler I ran this program
on is technically pre-ANSI, but I''ve kept the differences in mind (and
the documentation close at hand). I figured I could ask a K&R question,
though.
As to why I''m learning C on an Apple IIe.. I''m doing it to get used to
the compiler and the limitations of the computer. And because I''m
slightly nuts. :)
- Gio
--
AND NOW FOR A WORD (an IF blog):
http://giomancer.wordpress.com/
这篇关于K& R Ex 1-3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文登录 关闭
扫码关注1秒登录发送“验证码”获取 | 15天全站免登陆