-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d2a1b5
commit 2e506e8
Showing
14 changed files
with
325 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <stdio.h> | ||
int main(){ | ||
float a,b,c,m; | ||
scanf("%f %f %f",&a,&b,&c); | ||
m = a; | ||
if(b>=a){ | ||
m = b; | ||
if(c>=b){ | ||
m = c; | ||
} | ||
}else if (c>=a){ | ||
m = c; | ||
} | ||
printf("%f",m); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <stdio.h> | ||
#include <math.h> | ||
|
||
int isPrimenumber(int); | ||
|
||
int main() { | ||
int a, b; | ||
printf("请输入两个正整数 a 和 b (a <= b): "); | ||
scanf("%d %d", &a, &b); | ||
|
||
if (a > b || a <= 1) { | ||
printf("%d 不是区间[1,%d]之间的有效数值\n", a, b); | ||
return 0; | ||
} | ||
|
||
if (isPrimenumber(a)) { | ||
printf("%d 是区间[1,%d]之间的素数\n", a, b); | ||
} else { | ||
printf("%d 不是区间[1,%d]之间的素数\n", a, b); | ||
} | ||
return 0; | ||
} | ||
|
||
int isPrimenumber(int a) { | ||
for (int i = 2; i <= sqrt(a); i++) { | ||
if (a % i == 0) { | ||
return 0; | ||
} | ||
} | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <stdio.h> | ||
|
||
int digit(int n, int k); | ||
|
||
int main() { | ||
int n, k; | ||
printf("分别输入整数和位数: "); | ||
scanf("%d %d", &n, &k); | ||
|
||
if (k <= 0) { | ||
printf("位数 k 必须大于 0\n"); | ||
return 1; | ||
} | ||
|
||
if (n < 0) { | ||
n = -n; | ||
} | ||
|
||
printf("整数 %d 从右边开始第 %d 位数字的值为 %d\n", n, k, digit(n, k)); | ||
return 0; | ||
} | ||
|
||
int digit(int n, int k) { | ||
int i; | ||
for (i = 0; i < k - 1; i++) { | ||
n = n / 10; | ||
} | ||
return (n % 10); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <stdio.h> | ||
#include <math.h> | ||
|
||
int isPerfect(int a); | ||
|
||
int main() { | ||
int i; | ||
for (i = 1; i < 1001; i++) { | ||
if (isPerfect(i)) { | ||
printf("%d\n", i); | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
int isPerfect(int a) { | ||
int i, sum = 1; | ||
if (a <= 1) { | ||
return 0; | ||
} | ||
for (i = 2; i <= sqrt(a); i++) { | ||
if (a % i == 0) { | ||
sum += i; | ||
if (i * i != a) { | ||
sum += a / i; | ||
} | ||
} | ||
} | ||
return sum == a; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <stdio.h> | ||
#include <math.h> | ||
|
||
int main() { | ||
float x[10], y[10], distance = 0.0; | ||
int i, j; | ||
for (i = 0; i < 10; i++) { | ||
printf("请输入第%d个点的 x 坐标: ", i + 1); | ||
scanf("%f", x + i); | ||
printf("请输入第%d个点的 y 坐标: ", i + 1); | ||
scanf("%f", y + i); | ||
} | ||
for (i = 0; i < 9; i++) { | ||
for (j = i + 1; j < 10; j++) { // 从 i+1 开始,避免重复计算 | ||
distance += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])); | ||
} | ||
} | ||
printf("十个点的距离和为:%f\n", distance); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <stdio.h> | ||
#include <math.h> | ||
#include <stdlib.h> | ||
int compare(const void *a, const void *b) { | ||
float fa = *(const float*)a; | ||
float fb = *(const float*)b; | ||
return (fa > fb) - (fa < fb); | ||
} | ||
|
||
int main(){ | ||
int n = 0; float a=0.0; | ||
printf("请输入你需要多少个数:"); | ||
scanf("%d",&n); | ||
while(n<1||n>20){ | ||
printf("输入无效!请重来!"); | ||
} | ||
float x[n]; | ||
for (int i = 0; i < n; i++) { | ||
printf("请输入第%d个数: ", i + 1); | ||
scanf("%f", &a); | ||
x[i]=abs(a); | ||
} | ||
qsort(x, n, sizeof(float), compare); | ||
|
||
printf("排序后的数组: \n"); | ||
for (int i = 0; i < n; i++) { | ||
printf("%.2f ", x[i]); | ||
} | ||
printf("\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <stdio.h> | ||
int main() { | ||
int x[5][6], i, j, min, min_row, min_column; | ||
for (i = 0; i < 5; i++) { | ||
printf("请输入第 %d 行的 6 个元素(空格分割): ", i + 1); | ||
for (j = 0; j < 6; j++) { | ||
scanf("%d", &x[i][j]); | ||
} | ||
} | ||
|
||
for (i = 0; i < 5; i++) { | ||
for (j = 0; j < 6; j++) { | ||
printf("%d ", x[i][j]); | ||
} | ||
printf("\n"); | ||
} | ||
min = x[0][0]; | ||
min_row = 0; | ||
min_column = 0; | ||
for (i = 0; i < 5; i++) { | ||
for (j = 0; j < 6; j++) { | ||
if (min >= x[i][j]) { | ||
min = x[i][j]; | ||
min_row = i; | ||
min_column = j; | ||
} | ||
} | ||
} | ||
printf("最小值为:%d,在第 %d 行 第 %d 列\n", min, min_row + 1, min_column + 1); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <stdio.h> | ||
#include <math.h> | ||
#include <float.h> | ||
int main() { | ||
float x[5][6],max[5]; | ||
int i=0, j=0; | ||
for (i = 0; i < 5; i++) { | ||
max[i] = -10000000; // 设置一个很小的初始值 | ||
} | ||
for (i = 0; i < 5; i++) { | ||
printf("请输入第 %d 行的 6 个元素(空格分割): ", (int)i + 1); | ||
for (j = 0; j < 6; j++) { | ||
scanf("%f", &x[(int)i][(int)j]); | ||
if (fabs(x[(int)i][(int)j]) > max[(int)i]) { | ||
max[(int)i] = fabs(x[(int)i][(int)j]); | ||
} | ||
} | ||
} | ||
printf("\n处理后的数组(每行元素除以其绝对值最大值):\n"); | ||
for (i = 0; i < 5; i++) { | ||
for (j = 0; j < 6; j++) { | ||
if (max[(int)i] == 0) { | ||
printf("NaN "); | ||
} else { | ||
printf("%12.6f ", x[(int)i][(int)j] / max[(int)i]); | ||
} | ||
} | ||
printf("\n"); | ||
} | ||
return 0; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include<stdio.h> | ||
#include<math.h> | ||
int main(){ | ||
int a,b,c,aba,abb,abc; | ||
scanf("%d %d %d",&a,&b,&c); | ||
aba=abs(a);abb=abs(b);abc=abs(c); | ||
if(aba>=abb){//|a|>=|b| | ||
if (abc>=aba){//|c|>=|a|>=|b| | ||
printf("%d %d %d",b,a,c); | ||
}else if(abb>=abc){//|a|>=|b|>|c| | ||
printf("%d %d %d",c,b,a); | ||
}else{//|a|>=|c|=>|b| | ||
printf("%d %d %d",b,c,a); | ||
} | ||
}else{//|b|>=|a| | ||
if (abc>=abb){//|c|>=|b|>=|a| | ||
printf("%d %d %d",a,b,c); | ||
}else if(aba>=abc){//|b|>=|a|>=|c| | ||
printf("%d %d %d",c,a,b); | ||
}else{//|b|>=|c|>=|a| | ||
printf("%d %d %d",a,c,b); | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include<stdio.h> | ||
#include<math.h> | ||
int main(){ | ||
int a,b,c; float avg,da,db,dc; | ||
scanf("%d %d %d",&a,&b,&c); | ||
avg = (a+b+c)/3;da=abs(a-avg);db=abs(b-avg);dc=abs(c-avg); | ||
// da, db, dc里最小的 | ||
if(da>=db){//da>db ,a不会是最接近的 | ||
if(db>=dc){//da>=db>=dc | ||
printf("%d",c); | ||
}else{ | ||
printf("%d",b); | ||
} | ||
}else{//db>da ,b不会是最接近的 | ||
if(da>=dc){//db>=da>=dc | ||
printf("%d",c); | ||
}else{ | ||
printf("%d",a); | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include<stdio.h> | ||
int main(){ | ||
int a; | ||
scanf("%d",&a); | ||
printf("十进制为:%d,八进制为:%o,十六进制为:%x",a,a,a); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <stdio.h> | ||
|
||
int main() { | ||
double max, min, result, x; | ||
max = 0.0; | ||
min = 0.0; | ||
|
||
for (x = -2; x < 2.5; x += 0.5) { | ||
result = x * x - 3.14 * x - 6; | ||
max = (result >= max) ? result : max; | ||
min = (result <= min) ? result : min; | ||
} | ||
|
||
printf("最大值为:%f,最小值为:%f\n", max, min); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <stdio.h> | ||
|
||
int main() { | ||
int i, j; | ||
|
||
for (i = 0; i < 10; i++) { | ||
// µÚiÐпØÖÆ | ||
if (0 == i) { | ||
printf("\t(1)\t(2)\t(3)\t(4)\t(5)\t(6)\t(7)\t(8)\t(9)\n"); | ||
} else { | ||
// i = 1~9 | ||
for (j = 0; j < 10; j++) { | ||
if (0 == j) { | ||
printf("(%d)\t", i); | ||
} else { | ||
printf("%d\t", i * j); | ||
if (9 == j) { | ||
printf("\n"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return 0; | ||
} |
Binary file not shown.