C课程项目 [英] C Lessons Project

查看:85
本文介绍了C课程项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我发现的这些日常课程中学习C编程。他们已经十一天了,所以你们已经很忙了......

http://www.visualcmaniac.com

Learn C programming from these daily lessons I found. They''re eleven
days ahead of you already so get busy...

http://www.visualcmaniac.com

推荐答案


vu*****@gmail.com 写道:
从这些日常课程中学习C编程我发现。他们已经提前11天了,所以忙着......

http://www.visualcmaniac.com

不要!除非你想学习如何写*坏* C类程序。


这就是为什么(课程12):

#include< stdio.h>
#include< math.h>


没有必要包含math.h,因为它未在下面使用

void main(){


在此之后,所有投注都已关闭。看着粉红色的猪爬出你的耳朵

(未定义的行为,`main`必须返回'int`)。

int i,n,prime = 1; // prime是真的


这样的评论在C99中没问题。

printf("输入自然数:");


不使用\ n终止`printf`使得

实现可以不打印任何内容(至少不在firts之前\ n

它看到了。)

scanf("%d",& n);


无错误检查。如果用户输入的内容不是整数,那该怎么办?

即使输入了整数,如果它是负数呢?

for(i = 2; i< ; = n-1; i ++){

if(n%i == 0){//也可以陈述if(!(n%i))


更好地适当地加括号:


if((n%i)== 0){//也可以

状态if( !(n%i))

prime = 0; //素数现在是假的
休息;

}

如果(素数)

printf(" %d是素数!\ n",n);

其他

printf("%d不是素数!\ n,n );

}
Learn C programming from these daily lessons I found. They''re eleven
days ahead of you already so get busy...

http://www.visualcmaniac.com
DON''T! Unless you want to learn how to write *bad* C-like programs.

And here''s why ("Lesson" 12):
#include <stdio.h>
#include <math.h>
Not necessary to include math.h as it''s not used below
void main() {
After this, all bets are off. Watch pink pigs crawl out your ears
(undefined behaviour, `main` has to return `int`).
int i, n, prime=1; // prime is true
Comments like these are OK in C99.
printf("Input natural number :");
Not terminating `printf` with \n makes it possible for the
implementation to NOT print anything out (at least not before firts \n
it sees).
scanf("%d", &n);
No error checking. What if user enters something that''s not an integer.
Even if integer is entered, what if it''s negative?
for( i=2; i<= n-1; i++) {

if( n % i == 0 ) { // also possible to state if(!(n % i))
Much better to parenthesise appropriatelly:

if( (n % i) == 0 ) { // also possible to
state if(!(n % i))
prime =0; // prime is now false
break;

}
}

if( prime )

printf("%d is prime number !\n", n);

else

printf("%d isn''t prime number!\n", n);

}




间距很糟糕(或者如果你愿意的话,也很邋。)。


我没有检查所使用的算法是否也是正确的。



Spacing is atrocious (or sloppy, if you will).

I didn''t check whether the algorithmu used is actually correct either.


vu ***** @ gmail.com 说:
从我发现的这些日常课程中学习C编程。他们已经提前11天了,所以忙着......

http://www.visualcmaniac.com
Learn C programming from these daily lessons I found. They''re eleven
days ahead of you already so get busy...

http://www.visualcmaniac.com




如果这些课程应该教授C,那么它们就会失败。如果他们应该给某些特定于平台的C版本教授,那么他们在这里是偏离主题的。

-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)



If these lessons are supposed to teach C, they fail. If they are supposed to
teach some platform-specific variant of C, they are off-topic here.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


Vladimir S. Oka写道:
Vladimir S. Oka wrote:
vu*****@gmail.com 写道:
学习C从我发现的这些日常课程编程。他们已经提前11天了,所以忙着......

http://www.visualcmaniac.com
Learn C programming from these daily lessons I found. They''re eleven
days ahead of you already so get busy...

http://www.visualcmaniac.com


这样的评论在C99中没问题。

Comments like these are OK in C99.

printf(" Input)自然数:");
printf("Input natural number :");



不使用\ n终止`printf`使
实现无法打印出任何内容(至少在打印之前不会打印出来) \\ n
它看到了。)



Not terminating `printf` with \n makes it possible for the
implementation to NOT print anything out (at least not before firts \n
it sees).




< snip>


你能解释一下吗...好像你说的那样,比如说,


printf(输入一个数字>);


可能会导致在printf没有输出任何东西?


-

==============

*不是学究者*

==============



<snip>

Could you explain this please ... seems like you''re saying that, say,

printf("Enter a number >");

might result in printf not outputting anything?

--
==============
*Not a pedant*
==============


这篇关于C课程项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆