0%

C语言大题题库1

C语言大题题库1

题库内容过多,为了避免博客篇章过长,我将会分成多篇博客上传。

读四个数,计算,格式输出

image-20231005151459814

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <string.h>
#include<stdio.h>

int main() {
double num1, num2,num3,num4;
printf("请输入四个数:");
scanf("%lf%lf%lf%lf", &num1, &num2, &num3, &num4);
double result;
result = (((int)num1 % (int)num2) * num3) + num4;
printf("\n计算结果为:%016.7f", result);
//计算结果的输出格式为 %016.7f。这表示总宽度为16个字符,其中包含小数点以及小数点后面的7位数字。
return 0;
}//结果和图中一样

华氏温度转摄制温度

image-20231005152600514

1
2
3
4
5
6
7
8
9
10
11
12
#include <string.h>
#include<stdio.h>

int main() {
printf("请输入华氏温度:");
double F,C;
scanf("%lf", &F);//读取float用f,double(双精数浮点数)时用lf
printf("\n%f", F);
C = (5 * (F - 32))/9;
printf("\nF(%f)=C(%f)", F, C);
return 0;
}//结果和图中一样

小写字符输出ascii与转大写

image-20231005153338166

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <string.h>
#include<stdio.h>

int main() {
printf("请输入一个小写字母:");
char input,result;
scanf("%c", &input);
int gap;
gap = 'a' - 'A';//注意,小写的ascii是大于大写的
result = input - gap;
printf("%d", gap);
printf("\n%c(%d)", input, input);
printf("\n%c(%d)", result, result);
return 0;
}//输出和题目一样

求圆的周长面积,圆柱体积

image-20231005155213170
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <string.h>
#include<stdio.h>

int main() {
printf("输入r=,h=:");
double r, h;
double C, S, V;
scanf("r=%lf,h=%lf", &r, &h);
C = 6.28 * r;
S = r * r * 3.14;
V = S * h;
printf("\nC1=%.2lf\nS=%.2lf\nV=%.2lf", C, S, V);
}
//基础问题,不过scanf按格式输入值得注意
//有些我觉得有讲究的就会放出运行图
//其他的结果我都是运行过的,和题目的例子几乎一样

image-20231005155658493

输入年月日 处理后输出

image-20231006150908628

1
2
3
4
5
6
7
8
#include <string.h>
#include<stdio.h>

int main() {
int Y, M, D;
scanf("%d-%d-%d", &Y, &M, &D);
printf("%d/%02d/%02d",Y,M,D);
}

image-20231006151539513

读字符,输出ascii的十六进制

image-20231006152011370

1
2
3
4
5
6
7
8
9
10
#include <string.h>
#include<stdio.h>

int main() {
char inp;
printf("请输入一个字符:");
scanf("%c", &inp);
printf("\nAscii('%c') = 0x%X", inp,inp);
return 0;
}

输入正整数,逆序输出

image-20231006152342820

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <string.h>
#include<stdio.h>

int main() {
int in;
printf("请输入一个正整数:");
scanf("%d", &in);
if (in < 0) {
printf("请输入正整数");
}
else {
int ge;
ge = in % 10;
int shi;
shi = (in / 10) % 10;
int bai;
bai = (in / 100) % 10;

int result;
result = ge * 100 + shi * 10 + bai;
printf("结果是:%03d", result);
}
return 0;
}

读字符,范围输出

image-20231006154648740

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <string.h>
#include<stdio.h>

int main() {
char forth, lower;
int gap;
printf("请输入两个字符:");
scanf("%c%c", &forth, &lower);
printf("\n");
if (forth > lower) {
gap = forth - lower;
for (int i = 0; i <= gap; i++) {
printf("%c", lower + i);
}
}
else if (forth < lower) {
gap = lower - forth;
for (int i = 0; i <= gap; i++) {
printf("%c", forth + i);
}
}
else {
printf("%c", forth);
}
return 0;
}

image-20231006154702134

我的更好,我能判断大小捏!

输入三角形边长,算面积,根号

image-20231007211957366

这次的程序涉及到了根号的运算,难上加难了哈

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <math.h>//sqrt求根号需要用到
#include<stdio.h>

int main() {
int a, b, c;
double p, q;
printf("请输入三角形的三个边长:");
scanf("%d%d%d", &a, &b, &c);
if ((a + b > c) && (a + c > b) && (b + c > a)) {
p = (a + b + c) / (double)2;
q = (sqrt(p * (p - a) * (p - b) * (p - c)));//求根函数
printf("\n面积为:%lf", q);
}
else {
printf("\n请输入正确的三角形");
}
return 0;
}

输入三个整数,输出绝对值最大的

image-20231007212908310

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<stdio.h>

int main() {
printf("请输入三个整数:");
int arr[3],arr2[3];//第二个数组用来存储绝对值之后的数组1
//随后用索引的方式来存储绝对值最大的
scanf("%d%d%d", &arr[0], &arr[1], &arr[2]);
int max = arr[0];
int max_index = 0;
for (int i = 0; i < 3; i++) {
arr2[i] = arr[i];
if (arr[i] < 0) {
arr2[i] = -arr[i];
}
if (arr2[i] > max) {
max = arr2[i];
max_index = i;
}
}
printf("\n绝对值最大数是:%d", arr[max_index]);
}

这道题有意思,我还想了一会。

image-20231007214236159

根据输入输出特定矩阵

image-20231007214536718

有意思,第一瞬间没想到思路,故写一下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>

int main() {
printf("请输入一个整数:");
int a,arr[5];
scanf("%d", &a);
printf("\n");
arr[0] = a;
for (int i = 1; i < 5; i++) {
arr[i] = a + i;
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
printf("%4d", arr[i]+j);
}
printf("\n");
}
return 0;
}

image-20231007215050632

我是编程天才吗

判断是否是回文

image-20231010205253868

image-20231010205258083

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<stdio.h>
#include<string.h>

int main() {
printf("请输入一个字符串:");
char str[128];
int len;
gets_s(str);
len = strlen(str);
int j = len-1;//用来遍历从后往前
for (int i = 0; i < len - 1; i++) {
if (str[i] == str[j]) {
j--;//从后往前
}
else {
printf("\n不是回文");
return 0;
}
}
printf("\n是回文");

return 0;
}

image-20231010210425387

立方和等于规定num

image-20231010210547670

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
#include<string.h>

int main() {
printf("请输入一个整数:");
int num;
scanf("%d", &num);
printf("\n");
//因为只要求了三位数,所以循环三位数就可以
for (int i = 100; i < 1000; i++) {
int ge, shi,bai;
ge = i % 10;
shi = (int)(i / 10) % 10;
bai = (int)(i / 100) % 10;
if ((ge * ge * ge + shi * shi * shi + bai * bai * bai) == num) {
printf("%5d", i);
}
}
return 0;
}

image-20231010211524684

文本文件读等式并计算

image-20231010221422170

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
#include<string.h>

int main() {
FILE* fp = fopen("Comp.txt", "r");
int a, b;
char op;
//while ((ch = fgetc(fp)) != EOF) {//while中的条件是检测是否读取到文件末尾或者是否出错
// str[i] = ch;//将数据读取到字符串中去
// i++;
//}

//但是上述方法是不行滴
fscanf(fp, "%d %c %d", &a, &op, &b);//这个东西可以按格式读取
if (op == '+') {
int re = a + b;
printf("结果是:%d", re);
FILE* fp2 = fopen("Comp2.txt", "w");//w模式打开方便写东西
fprintf(fp2, "%d %c %d = %d", a, op, b, re);
fclose(fp2);
}
else if (op == '-') {
int re = a - b;
printf("结果是:%d", re);
fprintf(fp, "%d %c %d = %d", a, op, b, re);
FILE* fp2 = fopen("Comp2.txt", "w");
fprintf(fp2, "%d %c %d = %d", a, op, b, re);
fclose(fp2);
}
fclose(fp);
return 0;
}

image-20231010221503753

image-20231010221512213

输入三行三列的矩阵,求和

image-20231011223859342

image-20231011223903443

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<stdio.h>
#include<string.h>

int main() {
int arr[3][3];
printf("请输入一个三阶矩阵:\n");
for (int i = 0; i < 3; i++) {
scanf("%d %d %d", &arr[i][0], &arr[i][1], &arr[i][2]);
}
int sum = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
sum += arr[i][j];
}
}
printf("\nsum = %d", sum);
return 0;
}

image-20231011224340568

删除字符串中的星号

image-20231011224753198

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<stdio.h>
#include<string.h>

int main() {
char arr[100] = "";
char brr[100] = "";
printf("请输入一串字符串:");
gets_s(arr);
int len = strlen(arr);
int j = 0;
for (int i = 0; i < len; i++) {
if (arr[i] == '*') {
;
}
else {
brr[j] = arr[i];
j++;
}
}

printf("%s", brr);
return 0;
}

image-20231011225149241

输出能被3整出且h含有5的数

image-20231011225314818

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <string.h>

int main()
{
int m, n;
scanf("%d%d", &m, &n);
if ((m < 0 || n < 0) || (m > 1000 || n > 1000)) {
printf("请输入正确的0,1000的正整数。");
}
if (n < m) {
int t = m;
m = n;
n = t;
}//将小的放到n

int ge, shi, bai, qian;
printf("result:\n");
for (int i = m; i <= n; i++) {
if ((i % 3) == 0) {
ge = i % 10;
shi = (i / 10) % 10;
bai = (i / 100) % 10;
qian = (i / 1000) % 10;
if ((ge == 5) || (bai == 5) || (qian == 5)) {
printf("%6d", i);
}
}
}
}

image-20231021192537976

计算文本文件中的算式

image-20231023224929530

image-20231023224937777

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <string.h>

int main()
{
FILE* fp = fopen("comp.txt","r");
char string[200] = "";
if (fp == NULL) {
printf("打开文件失败!");
return 0;
}
int i = 0;
char ch;
int a, b, result;
char op;
while ((ch = fgetc(fp)) != EOF) {//不断循环看文件是否达到了末尾类似feof
fscanf(fp, "%d %c %d", &a, &op, &b);
if (op == '-') {
result = a - b;
printf("%d %c %d = %d\n", a, op, b, result);
}
else if (op == '+') {
result = a + b;
printf("%d %c %d = %d\n", a, op, b, result);
}
}

fclose(fp);
}//非常重要的一次编程!

image-20231023231637763

求一个矩阵的对角线元素之和

image-20231023232550298

image-20231023232557057

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <string.h>

int main()
{
int arr[20][20];
int m;
printf("请输入矩阵的阶数:");
scanf("%d", &m);
printf("\n请输入矩阵中的元素:\n");
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
printf("请输入第%d行第%d列的元素:\n",i,j);
int temp;
scanf("%d", &temp);//赋值
arr[i][j] = temp;
}
}

for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
printf("%5d", arr[i][j]);
}
printf("\n");
}

int sum = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
if (i == j) {
sum += arr[i][j];
}
}
}
printf("主对角线元素之和为:%d", sum);
}

//不用动态分配二维数组,直接分配好最大数量,然后使用即可。

image-20231023233218105

求公元纪元到指定日期的天数

image-20231024195300894

image-20231024195305751

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
int main(void)
{
int year, month, day, i;
int total[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
double sumyear = 0, summonth = 0, sum;
printf("input a data(year-month-day):");
scanf("%d-%d-%d", &year, &month, &day);
for (i = 1; i < year; i++)
{
if (i % 400 == 0 || i % 100 != 0 && i % 4 == 0)
{
sumyear += 366;
}
else
{
sumyear += 365;
}
}
for (i = 0; i < month; i++)
{
summonth += total[i];
}
if (year % 400 == 0 && month > 2 || year % 100 != 0 && year % 4 == 0 && month > 2)
{
summonth += 1;
}
sum = sumyear + summonth + day;
printf("The result is %.0lf.\n", sum);
return 0;
}

好难的题

字符数组相互穿插

image-20231024202653587

image-20231024202658531

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
int main(void)
{
char s1[127] = "";
char s2[127] = "";
char s3[300] = "";

printf("请输入数组1:");
scanf("%s", s1);
printf("\n请输入数组2:");
scanf("%s", s2);

int i = 0;
int j = 0;
int k = 0;
while (1) {
if (s1[i] == '\0') {//1走完了
if (s2[j] == '\0') {
printf("\n结果是:%s", s3);
return 0;
}//1走完了看2走完没
s3[k] = s2[j];
k++; j++;
}
else if (s2[j] == '\0') {//2走完了
if (s1[i] == '\0') {
printf("\n结果是:%s", s3);
return 0;
}//2走完了看1走完没
s3[k] = s1[i];
k++; i++;
}
else {
s3[k] = s1[i];
k++; i++;
s3[k] = s2[j];
k++; j++;
}
}
}

image-20231024204610377

找出最长单词

image-20231025184725381

image-20231025184729998

光看这个例子咱再怎么说也得把这道题写了把啊?毕竟是我的母校嘞(∩_∩)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <string.h>
int main(void)
{
printf("请输入一串字符:");
char ch[127] = "";
gets_s(ch);//若使用scanf,则会只读取一个单词
int len = strlen(ch);
char temp[127] = "";
int j = 0;
int max = 0;
for (int i = 0; i <= len; i++) {//第len个才是结束符!
if (ch[i] != ' ' && ch[i] != '\0') {//不要忘记结束符号!
temp[j] = ch[i];
j++;
}
else {
if (strlen(temp) > max) {
printf("\n22%s", temp);
max = strlen(temp);
}
strcpy(temp, "");//将最大的单词清零
j = 0;
}
}

printf("\n最大的单词长度是:%d", max);
}

image-20231025190839983

学生报数,排除第三个

image-20231025192953061

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>

#define MAX_STUDENTS 200

int main() {
int n;
printf("Please input n: ");
scanf("%d", &n);

if (n <= 3 || n >= MAX_STUDENTS) {
printf("Invalid input! n should be between 3 and 200.\n");
return 1;
}

int students[MAX_STUDENTS];
for (int i = 0; i < n; i++) {
students[i] = i + 1;
}

int count = 0;
int index = 0;
int remain = n;
printf("\nResult is:\n");

while (remain > 1) {
if (students[index] != 0) {
count++;
if (count == 3) {
printf("delete %d student: %d.\n", n - remain + 1, students[index]);
students[index] = 0;
count = 0;
remain--;
}
}
index++;
if (index == n) {
index = 0;
}
}

for (int i = 0; i < n; i++) {
if (students[i] != 0) {
printf("The remained student is %d.\n", students[i]);
break;
}
}

return 0;
}
//ai写的,太牛了,比标准答案简单捏。

输出人民币的汉字写法

image-20231025194136893

image-20231025194142109

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
printf("请输入一个整数:");
int n;
scanf("%d", &n);
while (n < 0 || n>2147483647) {
printf("\n数据错误,请重新输入:");
scanf("%d", &n);
}
printf("\n转换后端结果是: ");
char former[200];
_itoa(n, former, 10);//将n转换成字符串,10为转换后的进制
int len = strlen(former);
for (int i = 0, j = len; i < len; i++, j--) {
switch (former[i])
{
case '0':
printf("零");
break;
case '1':
printf("壹");
break;
case '2':
printf("贰");
break;
case '3':
printf("叁");
break;
case '4':
printf("肆");
break;
case '5':
printf("伍");
break;
case '6':
printf("陆");
break;
case '7':
printf("柒");
break;
case '8':
printf("捌");
break;
case '9':
printf("玖");
break;
default:
;
}
switch (j)
{
case 2:
case 6:
case 10:
printf("拾");
break;
case 3:
case 7:
printf("佰");
break;
case 4:
case 8:
printf("仟");
break;
case 5:
printf("万");
break;
case 9:
printf("亿");
break;
default:
169
;
}
}
printf("元整\n");
return 0;
}

这思路。。。牛批

螺旋数组来咯

看到螺旋数组了,今天手搓一个螺旋数组!我是Naruto,手搓螺旋丸😋

image-20231031212957420

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <string.h>

int main() {
printf("Enter n(n<=15):\n");
int n;
scanf("%d", &n);
printf("\n");
int arr[15][15];
int zuo, you, shang, xia;
zuo = 0;
you = n-1;
shang = 0;
xia = n-1;
int index = 1;
while ((zuo <= you)&&(shang <= xia)) {//注意这个等号
for (int i = zuo; i <= you; i++) {
arr[shang][i] = index;
//printf("%d\n", arr[shang][i]);
index++;//这个就是放进去的元素,每放一个就加一
}
shang++;
//最上面的边界往中间靠

for (int i = shang; i <= xia; i++) {
arr[i][you] = index;
index++;
//printf("%d\n", arr[i][you]);
}
you--;//最右边的边界往中间靠

for (int i = you; i >= zuo; i--) {
arr[xia][i] = index;
index++;
//printf("%d\n", arr[xia][i]);
}
xia--;//最下面的边界向上

for (int i = xia; i >= shang; i--) {
arr[i][zuo] = index;
index++;
//printf("%d\n", arr[i][zuo]);
}
zuo++;//左边边界收缩
}

//输出部分
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
printf("%5d", arr[i][j]);
}
printf("\n");
}
}

image-20231031212938154

好久没开电脑了。。最后一个月了!我要暴血了。。

未来的美好日子都是建立在我是研究生的基础上,我不想什么东西都失败。。。(┬┬﹏┬┬)让我上岸把。。我也不是笨猪啊T_T。自从上大学之后,除了入门网安之外。好像没有什么东西是真正意义上的成功过。。真的好累。。又不敢在其他地方发癫。自己博客也只敢😋偷偷插在文章中间发癫,不仔细看的大火肯定看不到捏。

二进制文件存储数据

image-20231117185102967image-20231117185106763

我们先用下面这串代码将数据内容用二进制的方式存进文件。

1
2
3
4
5
6
7
8
#include <stdio.h>
#include <string.h>
int main() {
FILE* f = fopen("./Comp.txt", "wb");
char string[127] = "xuebi da 6.00 345\nnongfuSQxianchengduo zhongxingA 4.392 57398\nxuebi xiao 2.004 4567\nxuebi da 6.003 456";
fprintf(f, "%s",string);
fclose(f);
}

然后开始弄

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <string.h>

struct Commodity {
char name[50]; // 商品名称
int count; // 商品数量
float price; // 商品价格
char size[50]; // 商品尺寸
} comarr[20];

void show(struct Commodity arr[20], int num);

int main() {
FILE* f = fopen("./Comp.txt", "r"); // 打开文件
if (f == NULL) {
printf("Failed to open file.\n"); // 打开文件失败
return 1;
}

char name[50];
int count;
float price;
char size[50];
int index = 0;

while (!feof(f) && index < 20) { // 循环读取文件内容直到文件结束或达到数组上限
// 从文件中读取商品信息,并检查是否成功读取了4个值
if (fscanf(f, "%s%s%f%d", name, size, &price, &count) == 4) {//注意这里的条件,fscanf会返回接收到的变量个数
strcpy(comarr[index].name, name); // 将商品名称复制到结构体数组中
strcpy(comarr[index].size, size); // 将商品尺寸复制到结构体数组中
comarr[index].count = count; // 将商品数量赋值给结构体数组中的count成员
comarr[index].price = price; // 将商品价格赋值给结构体数组中的price成员
index++; // 数组索引自增
}
}
fclose(f); // 关闭文件
show(comarr, index); // 调用显示函数,传入结构体数组和有效元素数量
}

void show(struct Commodity arr[20], int num) {
printf("情况如下:\n");
for (int i = 0; i < num; i++) {
printf("%s %s %d %f\n", arr[i].name, arr[i].size, arr[i].count, arr[i].price);
}
}

后面就不写了,无非就是查找,这个读取就已经竭尽全力了。。。。

查找用写

image-20231117193346122

时间结构体,计算时间差

image-20231129200451734

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <string.h>

struct Time {
int shi;
int fen;
int miao;
};

int main(){
int shi, fen, miao;
int shi1, fen1, miao1;
printf("请按照h-m-s的方式输入两个时刻:\n");
scanf("%d-%d-%d", &shi, &fen, &miao);
printf("\n");
scanf("%d-%d-%d", &shi1, &fen1, &miao1);

struct Time time_1, time_2;
time_1.shi = shi; time_1.fen = fen; time_1.miao = miao;
time_2.shi = shi1; time_2.fen = fen1; time_2.miao = miao1;

int a1 = time_1.shi * 60 * 60 + time_1.fen * 60 + time_1.miao;
int a2 = time_2.shi * 60 * 60 + time_2.fen * 60 + time_2.miao;

int result = a1 - a2;
if (result < 0) {
result *= (-1);
}

if (result >= 60 * 60) {
printf("两个时间相差%d个小时%d分钟%d秒\n", result / 3600, (result % 3600) / 60, (result % 3600) % 60);
printf("%d", result);
return 0;
}
else if (result >= 60) {
printf("两个时间相差%d分钟%d秒\n", (result % 3600) / 60, (result % 3600) % 60);
return 0;
}
else {
printf("两个时间相差%d秒\n", (result % 3600) % 60);
return 0;
}
}
//完全正确!