Skip to content

c practices level1 -- 孔淳漳#28

Open
Knorringite wants to merge 14 commits intoluckymark:masterfrom
Knorringite:master
Open

c practices level1 -- 孔淳漳#28
Knorringite wants to merge 14 commits intoluckymark:masterfrom
Knorringite:master

Conversation

@Knorringite
Copy link
Copy Markdown

No description provided.

@Knorringite
Copy link
Copy Markdown
Author

05-07

@Knorringite Knorringite changed the title c practices 01- 04 -- 孔淳漳 c practices level1 -- 孔淳漳 Mar 5, 2017
@luckymark luckymark requested review from gutouyu and luckymark March 8, 2017 13:30
Copy link
Copy Markdown
Owner

@luckymark luckymark left a 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 (" ");
}
Copy link
Copy Markdown
Owner

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++)
Copy link
Copy Markdown
Owner

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--)
Copy link
Copy Markdown
Owner

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;
Copy link
Copy Markdown
Owner

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);
Copy link
Copy Markdown
Owner

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++)
Copy link
Copy Markdown
Owner

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>
Copy link
Copy Markdown
Owner

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];
Copy link
Copy Markdown
Owner

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)
Copy link
Copy Markdown
Owner

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)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缩进+大括号

@Knorringite
Copy link
Copy Markdown
Author

= =

@Knorringite
Copy link
Copy Markdown
Author

add 08-09

@Knorringite
Copy link
Copy Markdown
Author

好久没提交作业了。。。。不是因为懒,而是恶补。。。

@Knorringite
Copy link
Copy Markdown
Author

继续写。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants