-
Notifications
You must be signed in to change notification settings - Fork 35
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
再次尝试 #43
base: master
Are you sure you want to change the base?
再次尝试 #43
Changes from 4 commits
325566b
d32e9e8
c4f37f2
b2a8cc6
5fbf301
fe538e3
74c8110
660b967
af9913b
a70f336
5f064be
63ca7af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include<stdio.h> | ||
#include<windows.h> | ||
#define boundry 80 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 习惯上常数用全大写 |
||
|
||
int i = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i也做成全局变量,有点过分吧 |
||
void move(); | ||
void main() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加一个空行 |
||
{ | ||
for (i = 0;i < boundry;i++) { | ||
move(); | ||
} | ||
for (i = boundry;i >= 0;i--) { | ||
move(); | ||
} | ||
} | ||
|
||
void move() | ||
{ | ||
Sleep(50); | ||
system("cls"); | ||
for (int j = 0;j < i - 1;j++) { | ||
printf(" "); | ||
} | ||
printf("R"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include<stdio.h> | ||
|
||
int main() | ||
{ | ||
long int i, j; | ||
|
||
printf("Please input a number: \t"); | ||
scanf_s("%d", &i); | ||
|
||
if (i == 2) { | ||
printf("%d is a Prime.", i); | ||
} | ||
else if (i == 1) { | ||
printf("%d is not a Prime.", i); | ||
} | ||
else { | ||
j = 2; | ||
while (i > j) { | ||
if (i%j == 0) { | ||
break; | ||
} | ||
else{ | ||
if (i == j + 1){ | ||
printf("%d is a Prime.", i); | ||
break; | ||
} | ||
j++; | ||
|
||
} | ||
} | ||
|
||
if (i > j + 1) | ||
printf("%d is not a Prime.", i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加个大括号 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include<stdio.h> | ||
int main() | ||
{ | ||
int i, j, k, l; | ||
for (i = 100;i < 1000;i++) | ||
{ | ||
k = i % 10; | ||
j = (i % 100) / 10; | ||
l = i / 100; | ||
if (i == (k*k*k) + (j*j*j) + (l*l*l)) | ||
{ | ||
printf("%5d", i); | ||
} | ||
} | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include<stdio.h> | ||
|
||
void main() | ||
{ | ||
int one, ten, hun; | ||
|
||
for (int num= 100;num < 1000;num++) | ||
{ | ||
one = num % 10; | ||
ten = (num % 100) / 10; | ||
hun = num / 100; | ||
if (num == (one*one*one) + (ten*ten*ten) + (hun*hun*hun)) | ||
{ | ||
printf("%5d", num); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
##define _CRT_SECURE_NO_WARNINGS//����̵� | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 中文乱码了,源文件最好用utf-8编码 |
||
#include<stdio.h> | ||
#include<stdlib.h> | ||
|
||
void turnup(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 单词之间用下划线分隔一下,或者用驼峰命名也不错 |
||
void turndown(); | ||
void turnleft(); | ||
void turnright(); | ||
void show(); | ||
|
||
char A[22][22]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A这个名字是什么意思呢? |
||
char *p; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这几个变量不宜为全局变量 |
||
int i, j, x=20, y=0; | ||
char step; | ||
int point = 'R'; | ||
|
||
int main() | ||
{ | ||
p = A[0]; | ||
FILE *fp; | ||
fp = fopen("mazemap.txt", "r"); | ||
|
||
if (fp == NULL) { | ||
printf("can't open"); | ||
exit(1); | ||
} | ||
|
||
for (;p < A[0] + 484;p++) { | ||
fscanf_s(fp, "%c", p); | ||
if ((p - A[0]) % 22 == 0) { | ||
i += 1; | ||
j = 0; | ||
} | ||
j++; | ||
} | ||
A[x][y] = 'R';; | ||
show(); | ||
|
||
while (x > 0 || y < 20) { | ||
step = _getch(); | ||
switch (step){ | ||
case 'w': { | ||
turnup(); | ||
break; | ||
} | ||
case 'a': { | ||
turnleft(); | ||
break; | ||
} | ||
case 'd': { | ||
turnright(); | ||
break; | ||
} | ||
case 's': { | ||
turndown(); | ||
break; | ||
} | ||
} | ||
} | ||
system("cls"); | ||
printf(" That's cool , you have win!\n"); | ||
getchar(); | ||
} | ||
|
||
|
||
void show() | ||
{ | ||
for (int i = 0;i < 22;i++) { | ||
for (int j = 0;j < 22;j++) { | ||
printf("%c", A[i][j]); | ||
if (j == 21)printf("\n"); | ||
} | ||
} | ||
} | ||
|
||
|
||
void turnup() | ||
{ | ||
if (A[x - 1][y] != '*') { | ||
A[x][y] = ' '; | ||
A[x - 1][y] = point; | ||
system("cls"); | ||
show(); | ||
x = x - 1; | ||
} | ||
} | ||
|
||
|
||
void turnleft() | ||
{ | ||
if (A[x][y - 1] != '*') { | ||
A[x][y] = ' '; | ||
A[x][y - 1] = point; | ||
system("cls"); | ||
show(); | ||
y = y - 1; | ||
} | ||
} | ||
|
||
|
||
void turnright() | ||
{ | ||
if (A[x][y + 1] != '*') { | ||
A[x][y] = ' '; | ||
system("CLS"); | ||
A[x][y + 1] = point; | ||
show(); | ||
y = y + 1; | ||
} | ||
} | ||
|
||
|
||
void turndown() | ||
{ | ||
if (A[x + 1][y] != '*') { | ||
A[x][y] = ' '; | ||
A[x + 1][y] = point; | ||
system("cls"); | ||
show(); | ||
x += 1; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
void main() | ||
{ | ||
int t = 1,m,n; | ||
int c[101] = { 0 }; | ||
int prime[26]; | ||
|
||
for (int a = 2;a <= 10;a++) { | ||
if (c[a] == 0) { | ||
for (int b = 2 * a;b <= 100;b += a) | ||
c[b] = 1; | ||
} | ||
} | ||
|
||
for (int a = 2;a <= 100;a++) { | ||
if (c[a] == 0) { | ||
prime[t] = a; | ||
t += 1; | ||
} | ||
} | ||
|
||
for (m = 1;m <= 50;m++) { | ||
n = 2 * m; | ||
for (int p = 1;p <= 26;p++) { | ||
for (int d = 1;d <= p;d++) { | ||
if (n == prime[p] + prime[d]) | ||
printf("%2d=%2d+%2d\t", n, prime[p], prime[d]); | ||
} | ||
} | ||
} | ||
printf("\n\n"); | ||
|
||
if (m = 50) { | ||
printf("��ˣ���100���ڸ�°ͺղ�����ȷ��"); | ||
} | ||
else { | ||
printf("��ˣ���100���ڸ�°ͺղ��벻��ȷ��"); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
void encrypt(); | ||
void decrypt(); | ||
|
||
int L = 5; | ||
char k, ch; | ||
char* p; | ||
int count = 0; | ||
|
||
int main() | ||
{ | ||
p = (char*)malloc(sizeof(char) * L); | ||
printf("��ѡ����������ܻ��ǽ���:a������ b������\n"); | ||
k = getch(); | ||
if (k == 'a') { | ||
encrypt(); | ||
} | ||
|
||
|
||
else if (k == 'b') { | ||
decrypt(); | ||
} | ||
else { | ||
printf("���������Ϣ����."); | ||
return 0; | ||
} | ||
} | ||
|
||
|
||
void encrypt() | ||
{ | ||
printf("������������ܵ��ַ���: "); | ||
do | ||
{ | ||
ch = getchar(); | ||
count++; | ||
if (count >= L) { | ||
p = (char*)realloc(p, sizeof(char*) * (++L)); | ||
} | ||
p[count - 1] = (char)((int)ch + 4); | ||
} while (ch != '\n'); | ||
printf("��һ������%d���ַ�\n���ܺ������Ϊ��", count - 1); | ||
for (int i = 0;i < count;i++) { | ||
printf("%c", p[i]); | ||
} | ||
free(p); | ||
} | ||
|
||
|
||
void decrypt() | ||
{ | ||
printf("������������ܵ��ַ���: "); | ||
do | ||
{ | ||
ch = getchar(); | ||
count++; | ||
if (count >= L) { | ||
p = (char*)realloc(p, sizeof(char*) * (++L)); | ||
} | ||
p[count - 1] = (char)((int)ch - 4); | ||
} while (ch != '\n'); | ||
printf("��һ������%d���ַ�\n���ܺ������Ϊ��", count - 1); | ||
for (int i = 0;i < count;i++) { | ||
printf("%c", p[i]); | ||
} | ||
free(p); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include<stdio.h> | ||
void han(int num, char a, char b, char c); | ||
|
||
int main() | ||
{ | ||
int num; | ||
printf("�����������ƶ��ĺ�ŵ��Բ��������"); | ||
scanf_s("%d", &num); | ||
printf("�ƶ�˳��Ϊ��\n"); | ||
han(num, 'a',' b',' c'); | ||
} | ||
|
||
void han(int num, char a, char b, char c) | ||
{ | ||
if (num == 1) { | ||
printf("%c�ƶ���%c\n", a, c); | ||
} | ||
else { | ||
han(num - 1, 'a',' c', 'b'); | ||
printf("%c�ƶ���%c\n", a, c); | ||
han(num - 1, 'b', 'a', 'c'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allPrimes.c 是什么鬼?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改多了改着改着就手误了,不好意思啊俸爷,马上改