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

2018081309027陶奕兮 #44

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions level0/C01.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include<stdio.h>
int main()
{
printf("Hello world!I'm tyx!");
}
12 changes: 12 additions & 0 deletions level0/C11.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include<stdio.h>
int main()
{
int n;
printf("Please put in a number:\n");
scanf("%d",&n);
if(n%2==0) printf("It's an even number.\n");
else printf("It's an odd number.\n");
if(n>0) printf("It's a positive number.\n");
else if(n==0) printf("It's zero.\n");
else printf("It's a negative number.\n");
}
9 changes: 9 additions & 0 deletions level0/C12.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include<stdio.h>
int main()
{
int n;
printf("Please put in a number:\n");
scanf("%d",&n);
if(n%13==0) printf("Yes.\n");
else printf("No.\n");
}
21 changes: 21 additions & 0 deletions level0/C210.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<stdio.h>
int main()
{
int b[5],c[10]={0};
printf("Please put in 5 numbers(between 0-9):\n");
for(int i=0;i<5;i++)
{
scanf("%d",&b[i]);
for(int t=0;t<10;t++)
{
if(b[i]==t) c[t]++;
}
}
for(int t=0;t<10;t++)
{
for(int i=1;i<=c[t];i++)
{
printf("%d,",t);
}
}
}
10 changes: 10 additions & 0 deletions level0/C22.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include<stdio.h>
#include<stdlib.h>
int main()
{
system("color 0a");
while(1)
{
printf("0 1");
}
}
10 changes: 10 additions & 0 deletions level0/C23.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include<stdio.h>
#include<stdlib.h>
int main()
{
system("color 0a");
while(1)
{
printf("%d\t",rand()/1000);
}
}
20 changes: 20 additions & 0 deletions level1/p01_runningLetter/1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<stdio.h>
Copy link
Owner

Choose a reason for hiding this comment

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

文件名应该有明确的含义,不宜使用1.cpp这样的,就像变量名不宜用abc一样;

#include<stdlib.h>
int main()
{
int i,wide=80;
bool turn;
for(i=0;;)
{
for(int t=0;t<=i;t++)
{
printf(" ");
}
printf("R");
system("cls");
if(i==wide) turn=1;
if(i<0) turn=0;
if(turn==0) i++;
else i--;
}
}
18 changes: 18 additions & 0 deletions level1/p02_isPrime/lv1_p02.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<stdio.h>
int main()
{
int n,ans=0;
printf("Please input a positive integer:\n");
scanf("%d",&n);
for(int t=2;t<=n/2;t++)
{
if(n%t==0)
{
ans=1;
break;
}
}
if(ans==1) printf("It's not a prime number.");
else printf("It's a prime number.");
return 0;
}
12 changes: 12 additions & 0 deletions level1/p03_Diophantus/lv1_p03.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include<stdio.h>
int main()
{
for(int age=1;;age++)
{
if(age/6+age/12+age/7+5+age/2+4==age)
{
printf("%d",age-4);
break;
}
}
}
16 changes: 16 additions & 0 deletions level1/p04_ narcissus/lv1_p04.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include<stdio.h>
int main()
{
int x,g,s,b;
for(x=100;x<=999;x++)
{
g=x%10;
s=((x-g)/10)%10;
b=(x-g-s)/100;
if(x==g*g*g+s*s*s+b*b*b)
{
printf("%d��",x);
}
}
getchar();
}
17 changes: 17 additions & 0 deletions level1/p05_allPrimes/lv1_p05.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
#include<time.h>
int main()
{
long t1,t2;
t1=clock();
for(int n=2;n<=1000;n++)
{
for(int t=2;t<=n/2+1;t++)
{
if(t==n/2+1) printf("%d,",n);
if(n%t==0) break;
}
}
t2=clock();
printf("\nTotally used %ld ms.\n",(t2-t1));
}
37 changes: 37 additions & 0 deletions level1/p06_Goldbach/lv1_p06.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include<stdio.h>
int is_p(int x)
{
for(int i=2;i<=x/2+1;i++)
{
if(i==x/2+1) return 1;
if(x%i==0)
{
return 0;
break;
}
}
}

int main()
{
int prime;
for(int t=4;t<101;t=t+2)
{
int m=2,n;
for(;;)
{
prime=is_p(m);
if(prime==1)
{
n=t-m;
prime=is_p(n);
if(prime==1)
{
printf("%d=%d+%d\n",t,m,n);
break;
}
}
m++;
}
}
}