-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
c practices level1 -- 孔淳漳 #28
base: master
Are you sure you want to change the base?
Conversation
05-07 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我暂时看到这里,请自己把后面的类似问题一并修改了,我再继续看
for (j = 0; j < i; j++) | ||
{ | ||
printf (" "); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
缩进没对齐
int i,j; | ||
system("mode con cols=16 lines=9"); | ||
int width = GetSystemMetrics ( SM_CXSCREEN ); | ||
for (i = 0; i < 16; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
循环控制变量,尽可能放进循环体内定义
printf ("%c", c); | ||
Sleep (100); | ||
} | ||
for(i = 15; i >= 0; i--) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
重复的味道!这两段循环有些相似,请消除
for (i = 2; i < n; i++) | ||
{ | ||
if(n % i == 0) | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有缩进;
因为是短路语句,此处不换行也很好,like this:if(n % i == 0) break;
如果换行的话,最好用大括号包起来;
break; | ||
} | ||
if(i == n) | ||
printf ("%d is a prime\n", n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
缩进+大括号
int main(void) | ||
{ | ||
int i; | ||
for (i=100; i < 1000; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
循环变量
哦,对了,需要修改编译选项才行,-std=c99,你的IDE里怎么设置,可以在群里咨询
@@ -0,0 +1,34 @@ | |||
#include <stdio.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前是C语言的作业,不能使用cpp做后缀,也不能使用c++的语法
{ | ||
float start, finish; | ||
start = clock(); | ||
bool prime[N]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool是c++的语法,在C语言里是不能用的
for(int i = 2; i < N; i++) | ||
{ | ||
if(prime[i]) | ||
for(int j = i * 2; j < N; j += i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
貌似这个算法不对吧,这样只把各种2的倍数搞掉了啊
for(int i = 2; i < N; i++) | ||
{ | ||
if(prime[i]) | ||
for(int j = i * 2; j < N; j += i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
缩进+大括号
= = |
add 08-09 |
好久没提交作业了。。。。不是因为懒,而是恶补。。。 |
继续写。。。 |
No description provided.