-
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
level1_1-6 #27
base: master
Are you sure you want to change the base?
level1_1-6 #27
Changes from 7 commits
47f6388
9d07958
14a8d60
299c3df
572f347
d46fc73
7ceb952
e37f704
ce5db59
bd8c719
fa1e116
b9a3cc1
4f5b3a9
4505dfc
7e9391f
16658eb
5462f17
0eb3bb8
cc9e3dc
398f1f9
cf04089
3211c9c
1008555
3e1b54d
bc5f092
1c52d45
8c0167a
f5d1ad5
e52e279
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,27 @@ | ||
#include<stdio.h> | ||
#include<windows.h> | ||
#define SPACE 50 | ||
void show(char *pos); | ||
int main() | ||
{ | ||
char pos[102] = { " " }; | ||
for(int i=0;i<100;i++) | ||
{ | ||
pos[i] = 'R'; | ||
show(pos); | ||
pos[i] = ' '; | ||
if(i==99) //字母碰到边界时变为递减 | ||
for(;i>=0;i--) | ||
{ | ||
pos[i] = 'R'; | ||
show(pos); | ||
pos[i] = ' '; | ||
} | ||
} | ||
return 0; | ||
} | ||
void show(char *pos) { | ||
printf("%s", pos); | ||
Sleep(SPACE); | ||
system("cls"); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
int IS(int); //判断是否为素数 | ||
int main() { | ||
int x; | ||
printf("输入一个正整数,程序判断它是否为素数(q to quit):"); | ||
while (scanf_s("%d", &x)) | ||
{ | ||
if (x == 1 || x == 2) { | ||
puts("是素数"); | ||
} | ||
else if (IS(x)) | ||
puts("是素数."); | ||
else puts("不是素数."); | ||
printf("输入一个正整数,程序判断它是否为素数(q to quit):"); | ||
} | ||
system("pause"); | ||
return 0; | ||
} | ||
int IS(int x) | ||
{ | ||
int i; | ||
int mark = 0; //创建标记 | ||
for (i = 2; i < x; i++) | ||
{ | ||
if (x%i == 0) | ||
{ | ||
mark = 1; //若被整除,标记mark为1 | ||
break; | ||
} | ||
}if (mark == 1) | ||
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. 格式有点乱 |
||
return 0; | ||
else return 1; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
|
||
void main() | ||
{ | ||
int i; | ||
for (i = 1; 28 * i != 21 * i + 4 * i + 252; i++) | ||
{ | ||
; | ||
} | ||
printf("丢番图的年纪是%d\n", i); | ||
system("pause"); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
int main() | ||
{ | ||
int a, b, c; | ||
for (a = 0; a <= 9; a++) | ||
{ | ||
for (b = 0; b <= 9; b++) | ||
{ | ||
for (c = 0; c <= 9; c++) | ||
{ | ||
if (a*a*a + b*b*b + c*c*c == a + 10 * b + 100 * c && !( b == 0 && c == 0)) //排除非三位数(0开头)的情况 | ||
printf("%d%d%d\n", c, b, a); | ||
} | ||
} | ||
} | ||
system("pause"); | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
#include<time.h> | ||
int isprinme(int a); | ||
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. prime拼写错了;P应该大写; |
||
int IS(int); | ||
int main() | ||
{ | ||
clock_t t1, t2; | ||
t1 = clock(); | ||
for(int i=2;i<=1000;i++) | ||
{ | ||
if (isprinme(i)) | ||
printf("%5d", 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. 加大括号 |
||
} | ||
t2 = clock(); | ||
printf("打印时间:%f秒",(double)(t2-t1)/CLOCKS_PER_SEC); | ||
system("pause"); | ||
return 0; | ||
} | ||
int isprinme(int a) | ||
{ | ||
int mark = 0; | ||
for (int i = 2; i < a; i++) | ||
{ | ||
if (a%i == 0) //用mark标记a已被整除 | ||
{ | ||
mark = 1; | ||
break; | ||
} | ||
|
||
} | ||
if (mark == 1) //检查标记 | ||
return 0; | ||
else return 1; | ||
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,57 @@ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
#include<string.h> | ||
int loadPrime(int* a); | ||
int isPrime(int x); | ||
int main() | ||
{ | ||
int prime[100] = {0}; | ||
int sum; | ||
sum=loadPrime(prime); | ||
for (int a = 4; a <= 100;a+=2 ) | ||
{ | ||
for (int i = 0; i < sum; i++) | ||
{ | ||
for (int j = 0; j < sum; j++) | ||
{ | ||
if (a == prime[i] + prime[j]) //遍历两个100以内的素数组合之和,与a作比较 | ||
{ | ||
printf("%d满足哥德巴赫猜想\n",a); | ||
goto b; //跳出遍历循环 | ||
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. 语句标号名取得不太好 |
||
} | ||
} | ||
} | ||
|
||
b: ; | ||
} | ||
system("pause"); | ||
return 0; | ||
} | ||
int isPrime(int x) | ||
{ | ||
int i; | ||
int mark = 0; //创建标记 | ||
for (i = 2; i < x; i++) | ||
{ | ||
if (x%i == 0) | ||
{ | ||
mark = 1; //若被整除,标记mark为1 | ||
break; | ||
} | ||
}if (mark == 1) | ||
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. 换行,缩进。。。 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. 其实,这里用?表达式也很爽 |
||
return 0; | ||
else return 1; | ||
} | ||
int loadPrime(int* a) | ||
{ | ||
int x = 0; | ||
for (int i = 1; i < 100; i++) | ||
{ | ||
if (isPrime(i)) | ||
{ | ||
a[x] = i; //把素数赋值给数组 | ||
x++; | ||
} | ||
} | ||
return x; //返回100以内的素数个数 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
#include<time.h> | ||
#define WIDTH 500 | ||
void encrypt(char* pt, int* pt2, int n); //加密函数 | ||
void decrypt(char* pt, int* pt2, int n); //解密函数 | ||
char* s_gets(char* st, int n); //获取输入 | ||
int main() | ||
{ | ||
char input[WIDTH] = { " " }; | ||
char num[WIDTH] = { 0 }; | ||
srand(time(NULL)); //用时间初始化随机数种子 | ||
for (int i = 0; i < WIDTH - 1; i++) //随机数组,供加密解密使用 | ||
{ | ||
num[i] = (int)rand()%10; | ||
} | ||
|
||
printf("输入待加密内容:"); | ||
s_gets(input, WIDTH - 1); | ||
encrypt(input,num,WIDTH-1); | ||
printf("加密后内容:%s\n", input); | ||
decrypt(input, num,WIDTH - 1); | ||
printf("解密后内容:%s\n", input); | ||
system("pause"); | ||
return 0; | ||
} | ||
void encrypt(char* pt,int* pt2,int n) | ||
{ | ||
for (int i = 0; i < n; i++) | ||
{ | ||
pt[i]+=pt2[i]; | ||
} | ||
} | ||
void decrypt(char* pt, int* pt2, int n) | ||
{ | ||
for (int i = 0; i < n; i++) | ||
{ | ||
pt[i] -=pt2[i]; | ||
} | ||
} | ||
char* s_gets(char* st, int n) | ||
{ | ||
char* ret_val; | ||
int i = 0; | ||
ret_val = fgets(st, n, stdin); | ||
if (ret_val) | ||
{ | ||
while (st[i] != '\n'&&st[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++; | ||
if (st[i] == '\n') | ||
st[i] = '\0'; | ||
else | ||
while (getchar() != '\n') | ||
continue; | ||
} | ||
return ret_val; | ||
} |
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.
适当加些空行