add hanshu
This commit is contained in:
parent
60d1a9d701
commit
bf87703ab3
BIN
Code/hanshu1
Normal file
BIN
Code/hanshu1
Normal file
Binary file not shown.
42
Code/hanshu1.c
Normal file
42
Code/hanshu1.c
Normal file
@ -0,0 +1,42 @@
|
||||
#include <stdio.h>
|
||||
|
||||
float Calculator(float a, float b, char operator)
|
||||
{
|
||||
switch (operator)
|
||||
{
|
||||
case '+':
|
||||
return a + b;
|
||||
case '-':
|
||||
return a - b;
|
||||
case '*':
|
||||
return a * b;
|
||||
case '/':
|
||||
if (b != 0) {
|
||||
return a / b;
|
||||
}
|
||||
else {
|
||||
printf("除数不能为0\n");
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
printf("用其它符号就不简单了哟 ^_^\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
float a, b;
|
||||
char operator;
|
||||
|
||||
printf("输入第一个数字: ");
|
||||
scanf("%f", &a);
|
||||
printf("输入运算符 (+, -, *, /): ");
|
||||
scanf(" %c", &operator);
|
||||
printf("输入第二个数字: ");
|
||||
scanf("%f", &b);
|
||||
|
||||
|
||||
printf("结果是:%.2f\n",Calculator(a, b, operator));
|
||||
|
||||
return 0;
|
||||
}
|
23
Code/hanshu2.c
Normal file
23
Code/hanshu2.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int exchange(int *a, int *b)
|
||||
{
|
||||
int temp = *a;
|
||||
*a = *b;
|
||||
*b = temp;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int a, b;
|
||||
printf("输入第一个数字: ");
|
||||
scanf("%d", &a);
|
||||
printf("输入第二个数字: ");
|
||||
scanf("%d", &b);
|
||||
|
||||
printf("交换前: a = %d, b = %d\n", a, b);
|
||||
exchange(&a, &b);
|
||||
printf("交换后: a = %d, b = %d\n", a, b);
|
||||
|
||||
return 0;
|
||||
}
|
BIN
Code/output/hanshu1
Normal file
BIN
Code/output/hanshu1
Normal file
Binary file not shown.
BIN
Code/output/hanshu2
Normal file
BIN
Code/output/hanshu2
Normal file
Binary file not shown.
BIN
Code/output/shuzu
Normal file
BIN
Code/output/shuzu
Normal file
Binary file not shown.
BIN
Code/output/shuzu1
Normal file
BIN
Code/output/shuzu1
Normal file
Binary file not shown.
BIN
Code/output/shuzu2
Normal file
BIN
Code/output/shuzu2
Normal file
Binary file not shown.
BIN
Code/output/test
BIN
Code/output/test
Binary file not shown.
BIN
Code/output/zhizhen1
Normal file
BIN
Code/output/zhizhen1
Normal file
Binary file not shown.
36
Code/shuzu1.c
Normal file
36
Code/shuzu1.c
Normal file
@ -0,0 +1,36 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int x;
|
||||
printf("请输入数组元素的个数:");
|
||||
scanf("%d", &x);
|
||||
int arr[x];
|
||||
for (int i = 0; i < x; i++)
|
||||
{
|
||||
printf("请输入第%d个元素:", i + 1);
|
||||
scanf("%d", &arr[i]);
|
||||
}
|
||||
|
||||
int max = arr[0];
|
||||
for (int i = 0; i < x; i++)
|
||||
{
|
||||
if (arr[i] > max)
|
||||
{
|
||||
max = arr[i];
|
||||
}
|
||||
}
|
||||
printf("最大值是:%d\n", max);
|
||||
|
||||
int min = arr[0];
|
||||
for (int i = 0; i < x; i++)
|
||||
{
|
||||
if (arr[i] < min)
|
||||
{
|
||||
min = arr[i];
|
||||
}
|
||||
}
|
||||
printf("最小值是:%d\n", min);
|
||||
|
||||
return 0;
|
||||
}
|
58
Code/shuzu2.c
Normal file
58
Code/shuzu2.c
Normal file
@ -0,0 +1,58 @@
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
int main()
|
||||
{
|
||||
int flag = 0,num = 0,count = 0;
|
||||
char name[20];
|
||||
char name_list[40][20];
|
||||
while(1)
|
||||
{
|
||||
printf("[1]记录名字 [2]显示已记录的同学的名字 [3]查询 [4]退出\n");
|
||||
scanf("%d", &flag);
|
||||
switch(flag)
|
||||
{
|
||||
case 1:
|
||||
printf("请输入记录人数:\n");
|
||||
scanf("%d", &num);
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
printf("请输入第%d个同学的名字:", i + 1);
|
||||
scanf("%s", name_list[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (name_list[0][0] == '\0')
|
||||
{
|
||||
printf("没有记录任何名字\n");
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
printf("第%d个同学的名字是:%s\n", i + 1, name_list[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
printf("请输入要查询的名字:");
|
||||
scanf("%s", name);
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
if (strcmp(name, name_list[i]) == 0)
|
||||
{
|
||||
printf("%s是第%d个同学的名字\n", name_list[i], i + 1);
|
||||
break;
|
||||
}
|
||||
if (i == num - 1)
|
||||
printf("没有找到该同学的名字\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
printf("退出程序\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
24
Code/test.c
24
Code/test.c
@ -2,9 +2,31 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
int x;
|
||||
printf("请输入数组元素的个数:");
|
||||
scanf("%d", &x);
|
||||
// if (x <= 0)
|
||||
// {
|
||||
// printf("回家吧,孩子,回家吧!\n");
|
||||
// return 1;
|
||||
// }
|
||||
int arr[x];
|
||||
for (int i = 0; i < x; i++)
|
||||
{
|
||||
printf("请输入第%d个元素:", i + 1);
|
||||
scanf("%d", &arr[i]);
|
||||
}
|
||||
|
||||
int max = arr[0], min = arr[0];
|
||||
for (int i = 0; i < x; i++)
|
||||
{
|
||||
if (arr[i] > max)
|
||||
max = arr[i];
|
||||
|
||||
|
||||
if (arr[i] < min)
|
||||
min = arr[i];
|
||||
}
|
||||
printf("最大值是:%d\n最小值是:%d\n",max ,min);
|
||||
|
||||
return 0;
|
||||
}
|
16
Code/zhizhen1.c
Normal file
16
Code/zhizhen1.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include<stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int array[5] = {10, 20, 30, 40, 50};
|
||||
|
||||
int *p = array;
|
||||
|
||||
printf("通过数组获取40:%d\n", array[3]);
|
||||
printf("通过数组获取40:%d\n", *(array+3));
|
||||
printf("通过指针获取40:%d\n", p[3]);
|
||||
printf("通过指针获取40:%d\n", *(p + 3));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user