C语言完美演绎9-15

/* 范例:9-15 */

#include <stdio.h>

#include <conio.h>

#include <string.h>

/* 没有自定义名称的typedef */

typedef struct{ char name10; int math_sco;} Scale1;

/* 有自定义类型名称的typedef */

struct Scale2

{

char name10;

int math_sco;

int eng_sco;

};

typedef struct Scale2 myScale;

/* 复位float在此文件中的代名 */

typedef float Average;

myScale myfuc(char a\[\],int b,int c)

{

myScale g;

strcpy(g.name,a);

g.math_sco = b;

g.eng_sco = c;

return g;

} /* struct也可以是函数的返回值 */

void main(void)

{

myScale b;

Average avg1;

b = myfuc("Robert",100,60);

printf("%s 数学%d分 英文%d分\n", \

b.name,b.math_sco,b.eng_sco);

avg1 = (b.math_sco + b.eng_sco)/2;

printf("平均%5.2f\n",avg1);

getchar();

}

程序执行结果:

Robert 数学100分 英文60分

平均80.00

相关推荐
爱读书的小胖19 小时前
Codewars:Rot13(C)解题分析
c语言·开发语言
Code_Solitude20 小时前
c语言:关于qsoet函数知识点
c语言·数据结构·算法
鸽鸽程序猿20 小时前
【项目】【在线判题系统】c端:竞赛报名
c语言·开发语言
H.莓飛21 小时前
【Linux】自主 Shell
linux·运维·服务器·c语言·开发语言·visual studio
爱读书的小胖1 天前
Codewars:Last digit of a large number(C)解题分析
c语言·开发语言·r语言
想做小南娘,发现自己是女生喵1 天前
第二周学习文档 Linux C 文件操作
linux·c语言·学习
Bluetooth7301 天前
c语言变量的存储类别
c语言
lhbweilai1 天前
分析FreeRTOS内核对象API的源码实现(四)
c语言·stm32·单片机
inrichtt1 天前
第八课时:SPI总线揭秘:四线全双工通信的奥
c语言·数据结构·stm32·单片机·嵌入式硬件
wuminyu1 天前
JMM学习总结:深入理解happens-before关系
java·linux·c语言·jvm·c++