33.对学生结构体的数据进行修改
2015-06-12 21:32
106 查看
程序通过定义学生结构体变量,存储了学号、姓名、和3门课的成绩,函数fun的功能是讲形参a中的数据进行修改,把修改后的数据作为函数值返回主函数进行输出。
#include<stdio.h> #include<string.h> struct student { long sno; char name[10]; float score[3]; }; struct student fun(struct student a) { int i; a.sno = 1002; strcpy_s(a.name,10, "LiSi"); for (i = 0;i < 3;i++) a.score[i]+= 1; return a; } int main() { struct student s = { 1001,"ZhangSan",95,80,88 }, t; int i; printf("\n\nThe original data:\n"); printf("\nNo:%ld Name:%s\nScore: ", s.sno, s.name); for (i = 0;i < 3;i++) printf("%6.2f", s.score[i]); printf("\n"); t = fun(s); printf("\nThe data after modified:\n"); printf("\nNo:%ld Name :%s\n Score: ", t.sno, t.name); for (i = 0;i < 3;i++) printf("%6.2f", t.score[i]); printf("\n"); getchar(); return 0; }
相关文章推荐
- 冒泡排序算法(优化版)
- “渴了么”软件详细说明书
- SpringMVC输入校验
- 冒泡排序算法
- 编译 android-x86-4.4 各种找不到,解决方法
- 百度地图API制作类似 百度地图的路线导航界面并实现简单的路线规划功能
- 让TableViewSection在Plan的模式下不悬浮
- Veins 数据包收发基本流程简单总结
- 动态规划:从新手到专家
- 冒泡排序算法(初级版)
- HLJU 1042 Fight (种类并查集)
- “渴了么”软件需求规格说明书
- [FZYZOJ 1200] 路由器安置
- ioctl错误引出的open和fopen的区别
- drp错误集锦---“Cannot return from outside a function or method”
- Precision/Recall和ROC曲线与分类
- Ubuntu 安装mysql和简单操作
- ios 获取 crash 日志
- 回车、换行、空格的ASCII码值—(附ASCII码表)
- 在VS上配置OpenCV