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

完成作业2018081302016 #43

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
20 changes: 20 additions & 0 deletions level1/p01_runningLetter/runningletter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>
#include <windows.h>
#include <math.h>
#define len 80
void blank(int i, int t){
int j;
for(;abs(i)!=t;i--){
for(j=0;j<=abs(i);j++){
printf(" ");
}
printf("H");
system("cls");
}
}
int main(){
blank(0, len);
blank(len, 0);
return 0;
}

19 changes: 19 additions & 0 deletions level1/p02_isPrime/isPrime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
int main(){
int i, j, n;
j=0;
scanf("%d", &n);
for(i=2;i<n;i++){
if(n%i==0){
j++;
}

}
if(j==0){
printf("%d is a prime",n);
}
else{
printf("%d is not a prime",n);
}
return 0;
}
13 changes: 13 additions & 0 deletions level1/p03_Diophantus/Diophantus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stdio.h>
int main(){
int i, t;
for(i=1;i<75;i++){
if(2*i%6==0 && 2*i%12==0 && 2*i%7==0){
if(i==2*i/6+2*i/12+2*i/7+9){
printf("when his son died, he is %d years old",2*i-4);
}
}
}
return 0;

}
16 changes: 16 additions & 0 deletions level1/p04_ narcissus/narcissus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdio.h>
int main(){
int i, j, k, a, b;
for(i=0;i<=9;i++){
for(j=0;j<=9;j++){
for(k=1;k<=9;k++){
a=k*100+j*10+i;
b=k*k*k+i*i*i+j*j*j;
if(a==b){
printf("%d ",a);
}
}
}
}
return 0;
}
21 changes: 21 additions & 0 deletions level1/p05_allPrimes/allPrime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdio.h>
#include <time.h>
int main(){
int i, j, t;
clock_t ts, te;
ts=clock();
for(i=2;i<=1000;i++){
t=0;
for(j=2;j<i;j++){
if(i%j==0){
t++;
}
}
if(t==0){
printf("%d \n",i);
}
}
te=clock();
printf("\n%d ms",te-ts);
return 0;
}
34 changes: 34 additions & 0 deletions level1/p06_Goldbach/Goldbach.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <stdio.h>
#define range 100
int isPrime(int num);
int main(){
int i, j, k, goldbach;
goldbach=0;
for(i=4;i<=range;i+=2){
for(j=2;j<=i/2;j++){
k=i-j;
if(isPrime(k) && isPrime(j)){
goldbach++;
break;
}
}
}
if(goldbach==range/2-1)
printf("%dis workable",range);
else
printf("%d is not workable",range);
return 0;
}
int isPrime(int num){
int i, t;
t=0;
for(i=2;i<num;i++){
if(num%i==0){
t++;
}
}
if(t==0)
Copy link
Owner

Choose a reason for hiding this comment

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

也可以写成:return t==0?1:0; 比较简洁一点

return 1;
else
return 0;
}
19 changes: 19 additions & 0 deletions level1/p08_hanoi/hannoi1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
#define N 64
void exchange(int n, char a, char b, char c) ;
int main(){
exchange(N, 'a', 'b','c');

}
void exchange(int n, char a, char b, char c){
if(n==1){
printf("%c->%c\n", a, c);
//return;
}
else{
exchange(n-1, a, c, b);
printf("%c->%c\n",a, c);
exchange(n-1,b, a, c);

}
}
Binary file added level1/p08_hanoi/hannoi1.exe
Binary file not shown.