21-32

 

 

 代码:

复制代码
 1 #pragma warning(disable:4996)
 2 #pragma warning(disable:6031)
 3 #pragma warning(disable:4700)
 4 #include <stdio.h>
 5 #include <string.h>
 6 
 7 
 8 int strLen(char* str) {
 9     int len = 0;
10     char* pStr = str;
11     while (*pStr != '\0') {
12         len++;
13         pStr++;
14     }
15     return len;
16 }
17 
18 int main() {
19     char str[100] = { 0 };
20     gets_s(str,100);
21     printf("%d\n", strlen(str));
22     return 0;
23 }
View Code
复制代码

 结果:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 代码:

复制代码
 1 #pragma warning(disable:4996)
 2 #pragma warning(disable:6031)
 3 #pragma warning(disable:4700)
 4 #include <stdio.h>
 5 #include <string.h>
 6 #define STUDENT_NUM 8
 7 #define COURSE_NUM 3
 8 
 9 /// <summary>
10 /// 编写课程结构体
11 /// </summary>
12 typedef struct CourseScore {
13     int ChineseScore;
14     int MathScore;
15     int EnglishScore;
16     char name[10];
17 }CourseScore;
18 /// <summary>
19 /// 编写学生结构体
20 /// </summary>
21 typedef struct StudentScore{
22     CourseScore courseScore;
23     int sumScore;
24 }StudentScore;
25 
26 void fun(StudentScore records[STUDENT_NUM]) {
27     int arrScore[COURSE_NUM] = {0};
28     for (int i = 0; i < 8; i++) {
29         arrScore[0] = records[i].courseScore.ChineseScore;
30         arrScore[1]= records[i].courseScore.MathScore;
31         arrScore[2] = records[i].courseScore.EnglishScore;
32         records[i].sumScore = records[i].courseScore.ChineseScore + records[i].courseScore.MathScore + records[i].courseScore.EnglishScore;
33     }
34 
35     for (int i = 1; i < STUDENT_NUM; i++) {
36         if (records[i - 1].sumScore > records[i].sumScore) {
37             StudentScore temp;
38             temp = records[i - 1];
39             records[i - 1] = records[i];
40             records[i] = temp;
41         }
42     }
43 }
44 
45 int main() {
46     StudentScore records[STUDENT_NUM] = { {90,95,83,"Mitt",0},{87,86,90,"Titt",0},{98,99,95,"Jorr",0},{88,85,80,"Tiatl",0},{81,80,83,"Jital",0},{88,95,80,"Mital",0},{98,95,80,"Kttal",0},{88,75,80,"Yormal",0} };
47     fun(records);
48     for (int i = 7; i >= 5; i--) {
49         printf("%d\t%.2f\t%s\n", records[i].sumScore, records[i].sumScore / 3.0, records[i].courseScore.name);
50     }
51     return 0;
52 }
View Code
复制代码

结果:

 

posted @   船长华莱士  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示