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

交作业啦 #35

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions level1/p01_runningLetter/running letter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include<stdio.h>
#include<windows.h>
int main()
{
int m = 10;
while (1)
{
for (int n = 0; n < m; n++)
{
for (int i = 0; i <= n; ++i)
{
printf("\n");
}
for (int i = 0; i <= n; ++i)
{
printf(" ");
}
printf("H");
Sleep(100);
system("cls");
}
for (int n = m; n > 0; n--)
{

for (int i = 0; i <= n; ++i)
{
printf("\n");
}for (int i = 0;i<=n; ++i)
{
printf(" ");
}
printf("H");
Sleep(100);
system("cls");
}
}
return 0;
}
27 changes: 27 additions & 0 deletions level1/p02_isPrime/isPrime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<stdio.h>
#include<math.h>
int main()
{
int n,flag=0;
scanf("%d", &n);
if (n == 2||n==1)
printf("yes\n");
else
{
for (int i=2; i <=sqrt(n); i++)
{
if (n % i == 0)
{
flag = 1;
break;
}

}
if (flag == 1)
printf("no\n");
else
printf("yes\n");
}

return 0;
}
14 changes: 14 additions & 0 deletions level1/p03_Diophantus/Diophantus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdio.h>

int main()
{
for(int i=1;i<100;++i)
{
if(i/2==i-(1.0/6*i+1.0/12*i+1.0/7*i+5+4))
{
printf("%d",i);
break;
}
}
return 0;
}
14 changes: 14 additions & 0 deletions level1/p04_ narcissus/narcissus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<stdio.h>
int main()
{
for (int i = 100; i <= 999; ++i)
{
int a = i / 100;
int b = i / 10 % 10;
int c = i % 10;
if (i ==a*a*a+b*b*b+c*c*c)
printf("%d\t", i);

}
return 0;
}
19 changes: 19 additions & 0 deletions level1/p05_allPrimes/prime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<stdio.h>
#include<math.h>
int main()
{
printf("2\t");
for (int i = 3; i <= 1000; ++i)
{
int k = 0;
for (int j = 2; j <= sqrt(i); ++j)
{
if (i % j == 0)
k = 1;

}
if (k == 0)
printf("%d\t", i);

}
}
38 changes: 38 additions & 0 deletions level1/p06_Goldbach/Goldbach.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>
#include <math.h>
int isPrime(int x)
{
int flag=1;
if(x>2)
{
for(int i=2;i<x;++i)
{
if(x%i==0) {
flag = 0;
break;
}
}
}
return flag;
}

int main()
{
for(int i=4;i<=100;i=i+2)
{
for(int j=2;j<i;++j)
{
if(isPrime(j)==1)
{
if(isPrime(i-j)==1)
{
printf("%d=%d+%d",i,j,i-j);
//printf("\t");
break;
}
}
}
printf("\n\n");
}
return 0;
}
68 changes: 68 additions & 0 deletions level1/p07_encrypt_decrypt/encrypt_decrypt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include<stdio.h>
#include<string.h>
#include<windows.h>
void crypt(int m)
{
char text[256] = { '\0' }, text1[256] = { '\0' };
if (m == 0)
{
printf("enter the words you want to encrypt:\n");
scanf("%s", text);
for (int i = 0; i <= int(sizeof(text)); i++)
{
if ((text[i] >= 'a' && text[i] <= 'z' )||( text[i] >= 'A' && text[i] <= 'Z'))//uvwxyz
{
if ((text[i] >= 'a' && text[i] <= 'u' )||( text[i] >= 'A' && text[i] <= 'U'))
{
text1[i] = text[i] + 5;
}
else
{
text1[i] = text[i] + 5 - 26;
}
}

}
printf("%s-->%s", text, text1);
}
else if (m == 1)
{
printf("enter the words you want to decrypt:\n");
scanf("%s", text);
for (int i = 0; i <= int(sizeof(text)); i++)
{
if ((text[i] >= 'a' && text[i] <= 'z' )||( text[i] >= 'A' && text[i] <= 'Z'))//uvwxyz
{
if ((text[i] >= 'e' && text[i] <= 'z' )||( text[i] >= 'E' && text[i] <= 'Z'))
{
text1[i] = text[i] - 5;
}
else
{
text1[i] = text[i] -5+26;
}
}

}
printf("%s<--%s", text, text1);
}
else
{
printf("error");
}
}

int main()
{
int m;
printf("press 0 to encrypt , press 1 to decrypt, press 2 to end the exe\n");
scanf("%d", &m);
while(m!=2)
{
crypt(m);
//system("cls");
printf("\npress 0 to encrypt , press 1 to decrypt, press 2 to end the exe\n");
scanf("%d", &m);
}
return 0;
}
36 changes: 36 additions & 0 deletions level1/p08_hanoi/hanio of function pointer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include<stdio.h>
int main()
{
int n;
char A='A',B='B',C='C';
printf("enter the number of plate you want to move:\n");
void hanio(int n,char a,char b,char c);
scanf("%d",&n);
hanio(n,A,B,C);
return 0;
}


void hanio(int n,char a,char b,char c)
{
void move(char a,char b);
void(*p)(char,char);
void(*q)(int,char,char,char);
q=hanio;
p=move;
if(n==1)
{
(*p)(a,c);
}
else
{
(*q)(n-1,a,c,b);
(*p)(a,c);
(*q)(n-1,b,c,a);
}
}

void move(char a,char b)
{
printf("%c -> %c\n",a,b);
}
32 changes: 32 additions & 0 deletions level1/p08_hanoi/hanio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<stdio.h>
int main()
{
int n;
char A='A',B='B',C='C';
printf("enter the number of plate you want to move:\n");
void hanio(int n,char a,char b,char c);
scanf("%d",&n);
hanio(n,A,B,C);
return 0;
}


void hanio(int n,char a,char b,char c)
{
void move(char a,char b);
if(n==1)
{
move(a,c);
}
else
{
hanio(n-1,a,c,b);
move(a,c);
hanio(n-1,b,c,a);
}
}

void move(char a,char b)
{
printf("%c -> %c\n",a,b);
}
Loading