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

xjq+1 #64

Open
wants to merge 9 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# c2019
# 大一c语言作业
#c2019

## 基本操作流程

Expand Down
32 changes: 32 additions & 0 deletions level1/p01_runningLetter/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <stdio.h>
#include <windows.h>
#define N 78
unsigned int sleep(unsigned int seconds);
int main()
{
int i,j;
while(1)
{
for(i=0;i<N;i++)
{
for(j = 0;j <= i;j++)
{
printf(" ");
}
printf("s");
Sleep(50);
system("cls");
}
for(i=N;i>0;i--)
{
for(j = 0;j <= i;j++)
{
printf(" ");
}
printf("s");
Sleep(100);
system("cls");
}
}
return 0;
}
38 changes: 38 additions & 0 deletions level1/p02_isPrime/sushu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>
int main()
{
int num,i,count = 0;
printf("input a number:");
scanf("%d",&num);
if(num <= 0)
{
printf("error!input again:");//��������һ��������
scanf("%d",&num);
}
else if(num == 1)
{
printf("N"); //1��������
}
else if(num == 2)
{
printf("Y"); //2������
}
else
{
for(i = 2;i < num;i++)
{
if(num%i == 0)
{
printf("N"); //��������
break;
}
else
{
count++;
}
}
if(count == (num - 2))
printf("Y"); //������
}
return 0;
}
14 changes: 14 additions & 0 deletions level1/p03_Diophantus/diufantu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdio.h>
//1/6x+1/12x+1/7x+5+1/2x+4=x
//ת��Ϊ14x+7x+12x+5*84+42x+4*84=84x
int main()
{
int i;
for(i = 0;i < 200;i++) //0-150ÿ����Ͷ����ԣ��ܻ�������ꡣ
{
if(14*i + 7*i + 12*i + 5*84 + 42*i + 4*84 == 84*i)
break;
}
printf("year = %d",i);
return 0;
}
22 changes: 22 additions & 0 deletions level1/p04_ narcissus/shuixian.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int a,b,c,i,num;

for(i=100;i<1000;i++)
{
num = i;
a=num%10;
num /= 10;
b=num%10;
num /= 10;
c = num;
if(i == (pow(a,3)+pow(b,3)+pow(c,3)))
{
printf("%d\n",i);
}
}
return 0;
}
29 changes: 29 additions & 0 deletions level1/p05_allPrimes/allprimes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
clock_t start, finish;
double cost;
int i,j;
start=clock();
printf("allPrimes:\n\n2 3 5 7 ");
for(i=5;i<1000;i += 2)
{
int count = 3;
for(j=3;j<i;j++)
{
if(i%j==0||i%3 == 0||i% 5==0||i%7==0)
break;
else
count++;
}
if(i == count)
printf("%-3d ",i);
}
printf("\n\n");
finish = clock();
cost = (double)(finish-start)/CLOCKS_PER_SEC;
printf("cost time : %lfs",cost);
return 0;
}
25 changes: 25 additions & 0 deletions level1/p06_Goldbach/newGoldbach.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <stdio.h>
int main()
{
int i,j,x,k;
int num ;
int primes[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
for(i = 4;i < 100;i += 2)
{

for(j = 0;j < 25;j++)
{
num = 0;
x = i - primes[j];
for(k = 0;k<25;k++)
{
if(x==primes[k])
num = 1;
}
if(!(x<2||num == 0||primes[j]>x))
printf("%-3d= %-3d+ %-3d\n",i,primes[j],x);
}
}
return 0;
}

26 changes: 26 additions & 0 deletions level1/p07_encrypt_decrypt/jiamitijiao.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 5 //��Կ
int main()
{
char password[50];
int i,count;
printf("��������Ҫ���ܵ����룺");
gets(password);
count = strlen(password);
for(i = 0;i < count;i++)
{
password[i] = password[i] + i + N;
}
system("cls");
printf("���ܺ������Ϊ��%s\n",password);
printf("���������������\n");
system("pause");
for(i = 0;i < count;i++)
{
password[i] = password[i] - i - N;
}
printf("���ܺ������ǣ�%s",password);
return 0;
}
24 changes: 24 additions & 0 deletions level1/p08_hanoi/hanoi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>
#include <math.h>
void hanoi(int,char,char,char);
int main()
{
int n;
printf("������Բ�̸�����");
scanf("%d",&n);
hanoi(n,'A','B','C');
int count = pow(2,n) - 1;
printf("һ����Ҫ%d����",count);
return 0;
}
void hanoi(int n,char a,char b,char c)
{
if(n == 1)
printf("%c-->%c\n",a,c);
else
{
hanoi(n - 1,a,c,b);
printf("%c-->%c\n",a,c);
hanoi(n - 1,b,a,c);
}
}
170 changes: 170 additions & 0 deletions level1/p09_maze/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <time.h>
#define Height 25 //�Թ��ĸ߶ȣ�����Ϊ����
#define Width 25 //�Թ��Ŀ��ȣ�����Ϊ����
#define Wall 1
#define Road 0
#define Start 2
#define End 3
#define Esc 5
#define Up 1
#define Down 2
#define Left 3
#define Right 4
int map[Height+2][Width+2];
void gotoxy(int x,int y) //�ƶ�����
{
COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
}
void hidden()//���ع��
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hOut,&cci);
cci.bVisible=0;//��1Ϊ��ʾ����0Ϊ����
SetConsoleCursorInfo(hOut,&cci);
}
void create(int x,int y) //��������Թ�
{
int c[4][2]={0,1,1,0,0,-1,-1,0}; //�ĸ�����
int i,j,t;
//���������
for(i=0;i<4;i++)
{
j=rand()%4;
t=c[i][0];c[i][0]=c[j][0];c[j][0]=t;
t=c[i][1];c[i][1]=c[j][1];c[j][1]=t;
}
map[x][y]=Road;
for(i=0;i<4;i++)
if(map[x+2*c[i][0]][y+2*c[i][1]]==Wall)
{
map[x+c[i][0]][y+c[i][1]]=Road;
create(x+2*c[i][0],y+2*c[i][1]);
}
}
int get_key() //���հ���
{
char c;
while(c=getch())
{
if(c==27) return Esc; //Esc
if(c!=-32)continue;
c=getch();
if(c==72) return Up; //��
if(c==80) return Down; //��
if(c==75) return Left; //��
if(c==77) return Right; //��
}
return 0;
}
void paint(int x,int y) //���Թ�
{
gotoxy(2*y-2,x-1);
switch(map[x][y])
{
case Start:
printf("��");break; //�����
case End:
printf("��");break; //������
case Wall:
printf("�~");break; //��ǽ
case Road:
printf(" ");break; //��·
}
}
void game()
{
int x=2,y=1; //��ҵ�ǰλ�ã��տ�ʼ����ڴ�
int c; //�������հ���
while(1)
{
gotoxy(2*y-2,x-1);
printf("��"); //������ҵ�ǰλ��
if(map[x][y]==End) //�ж��Ƿ񵽴����
{
gotoxy(30,24);
printf("�����յ㣬�����������");
getch();
break;
}
c=get_key();
if(c==Esc)
{
gotoxy(0,24);
break;
}
switch(c)
{
case Up: //������
if(map[x-1][y]!=Wall)
{
paint(x,y);
x--;
}
break;
case Down: //������
if(map[x+1][y]!=Wall)
{
paint(x,y);
x++;
}
break;
case Left: //������
if(map[x][y-1]!=Wall)
{
paint(x,y);
y--;
}
break;
case Right: //������
if(map[x][y+1]!=Wall)
{
paint(x,y);
y++;
}
break;
}
}
}
int main()
{
system("title yourname");
int i,j;
srand((unsigned)time(NULL)); //��ʼ���漴����
hidden(); //���ع��
for(i=0;i<=Height+1;i++)
for(j=0;j<=Width+1;j++)
if(i==0||i==Height+1||j==0||j==Width+1) //��ʼ���Թ�
map[i][j]=Road;
else map[i][j]=Wall;

create(2*(rand()%(Height/2)+1),2*(rand()%(Width/2)+1)); //�����һ���㿪ʼ�����Թ����õ����ж�Ϊż��
for(i=0;i<=Height+1;i++) //�߽紦��
{
map[i][0]=Wall;
map[i][Width+1]=Wall;
}

for(j=0;j<=Width+1;j++) //�߽紦��
{
map[0][j]=Wall;
map[Height+1][j]=Wall;
}
map[2][1]=Start; //�������
map[Height-1][Width]=End; //��������
for(i=1;i<=Height;i++)
{
for(j=1;j<=Width;j++) //�����Թ�
paint(i,j);
}
game(); //��ʼ��Ϸ
getch();
return 0;
}

Loading