Skip to content
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

level_1_p01.c to level_1_p06.c #40

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
21 changes: 21 additions & 0 deletions practices/c/level1/p01_runningLetter/level_1_p01.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<stdio.h>
#include<windows.h>
main()
Copy link
Owner

Choose a reason for hiding this comment

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

加个空行

{
for(int i=1;i<=50;i++){
for(int j=1;j<=i;j++){
printf(" ");
}
printf("R");
Sleep(10);
system("cls");
}
for(int i=50;i>=1;i--){
Copy link
Owner

Choose a reason for hiding this comment

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

闻到了重复的味道,这两个循环较相似,设法消除之

for(int j=i;j>=1;j--){
printf(" ");
}
printf("R");
Sleep(10);
system("cls");
}
}
15 changes: 15 additions & 0 deletions practices/c/level1/p02_isPrime/level_1_p02.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include<stdio.h>
main()
{
int a;
scanf("%d",&a);
if(a==1){
printf("非素数");}
for(int i=2;i<=a-1;i++){
if(a%i==0){
printf("非素数");
break;}
else
printf("素数");
}
}
14 changes: 14 additions & 0 deletions practices/c/level1/p03_Diophantus/level_1_p03.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<stdio.h>
main()
{
int ageDio;int ageSon;
int i,j;
for(i=1;i<=100;i++)
for(j=1;j<=100;j++){
ageDio=12*i*7*j;
ageSon=ageDio/2;
if(ageSon==((ageDio-4)-(ageDio*11/28+5))){
printf("%d",ageDio);
}
}
}
11 changes: 11 additions & 0 deletions practices/c/level1/p04_ narcissus/level_1_p04.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include<stdio.h>
main()
{
int a,b,c,result;int i;
for(a=1;a<=9;a++)
for(b=0;b<=9;b++)
for(c=0;c<=9;c++){
Copy link
Owner

Choose a reason for hiding this comment

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

缩进有点不齐

if(100*a+10*b+c==a*a*a+b*b*b+c*c*c)
printf("%d\n",100*a+10*b+c);
}
}
24 changes: 24 additions & 0 deletions practices/c/level1/p05_allPrimes/level_1_p05.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<stdio.h>
#include<math.h>
#include<time.h>
int prime(int);
main()
{
int i,j;
for(i=2;i<=1000;i++){
if(prime(i)>0)
printf("%d\n",i);
Copy link
Owner

Choose a reason for hiding this comment

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

缩进;
加大括号

}
printf("\n");
printf("%d",(int)clock());
Copy link
Owner

Choose a reason for hiding this comment

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

这样算时间有点不准,因为程序启动等时间也没包含在了里面

}

int prime(int m)
{
int k;int i;
k=sqrt(m);
for (i=2;i<=k;i++)
if (m%i==0) break;
Copy link
Owner

Choose a reason for hiding this comment

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

加上大括号吧,我这种老手看起来都晕,真不知道循环包含哪些语句呢

if (i>k) return m;
else return 0;
}
33 changes: 33 additions & 0 deletions practices/c/level1/p06_Goldbach/level_1_p06.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<stdio.h>
#include<math.h>
int checkprime(int m)
{
int k;int i;
k=sqrt(m);
for (i=2;i<=k;i++)
if (m%i==0) break;
Copy link
Owner

Choose a reason for hiding this comment

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

同上;
我感觉你的缩进跟实际的层次结构不对

if (i>k) return 1;
else return 0;
}

int main()
{
int a;int prime[100];int b;int c=0;

for(int i=2;i<=100;i++){
b=checkprime(i);
if(b==1){
prime[c]=i;
c++;
}

}
for(int i=2;i<=50;i++){
for(int j=0;j<=24;j++){
a=2*i-prime[j];
if(checkprime(a)==1){
printf("%d=%d+%d\n",2*i,a,prime[j]);break;
}
}
}
}