当前位置: 首页 > 编程日记 > 正文

抄写例题作业1

截图

1.例9.1

(1)代码实现

 1 #include<stdio.h>
 2 int main()
 3 {
 4     struct stu
 5     {
 6         long int num;
 7         char name[20];
 8         char sex[3];
 9         char addr[20];
10     }a={1010,"董诗原","","hkj"};
11     printf("No:%d\nname:%s\nsex:%s\naddr:%s",a.num,a.name,a.sex,a.addr);
12  } 

(2)运行结果

No:1010
name:董诗原
sex:男
addr:hkj
--------------------------------
Process exited after 0.4101 seconds with return value 0
请按任意键继续. . .

2.例9.2

(1)代码实现

 1 #include<stdio.h>
 2 int main()
 3 {
 4     struct stu
 5     {
 6         long int num;
 7         char name[20];
 8         float score;
 9     }stu1,stu2;
10     scanf("%d%s%f",&stu1.num,stu1.name,&stu1.score);
11     scanf("%d%s%f",&stu2.num,stu2.name,&stu2.score);
12     printf("The higher score is:\n");
13     if(stu1.score>stu2.score)
14     printf("%d %s %.2f\n",stu1.num,stu1.name,stu1.score);
15     else if(stu1.score<stu2.score)
16     printf("%d %s %.2f\n",stu2.num,stu2.name,stu2.score);
17     else{
18         printf("%d %s %.2f\n",stu1.num,stu1.name,stu1.score);
19         printf("%d %s %.2f\n",stu2.num,stu2.name,stu2.score);
20     }
21  } 

(2)运行结果

10101 wang 89
10103 ling 90
The higher score is:
10103 ling 90.00--------------------------------
Process exited after 25.17 seconds with return value 0
请按任意键继续. . .

3.例9.3

(1)代码实现

 1 #include<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5     struct per{
 6         char name[20];
 7         int count;
 8     }a[3]={"li",0,"zhang",0,"sun",0};
 9     char b[20];
10     for(int i=0;i<10;i++)
11     {
12         scanf("%s",&b);
13         if(strcmp(b,a[0].name)==0)
14         a[0].count++;
15         else if(strcmp(b,a[1].name)==0)
16         a[1].count++;
17         else
18         a[2].count++;
19     }
20     printf("\nResult:\nli:%d\nzhang:%d\nsun:%d\n",a[0].count,a[1].count,a[2].count);
21  } 

(2)运行结果

li
li
sun
zhang
zhang
sun
li
sun
zhang
liResult:
li:4
zhang:3
sun:3--------------------------------
Process exited after 55.91 seconds with return value 0
请按任意键继续. . .

4.例9.4

(1)代码实现

 1 #include<stdio.h>
 2 struct stu
 3 {
 4     long int num;
 5     char name[20];
 6     float score;
 7 };
 8 int main()
 9 {
10     struct stu t;
11     struct stu s[5]={10101,"zhang",78,10103,"wang",98.5,10106,"li",86,10108,"ling",73.5,10100,"sun",100 };
12     for(int i=0;i<5;i++){
13         for(int j=1;j<5-i;j++)
14         {
15             if(s[j].score>s[j-1].score)
16             {
17                 t=s[j];
18                 s[j]=s[j-1];
19                 s[j-1]=t;
20             }
21         }
22     }
23     for(int i=0;i<5;i++)
24     {
25         printf("%d%8s%8.2f\n",s[i].num,s[i].name,s[i].score); 
26     }
27 }

(2)运行结果

10100     sun  100.00
10103    wang   98.50
10106      li   86.00
10101   zhang   78.00
10108    ling   73.50--------------------------------
Process exited after 0.46 seconds with return value 0
请按任意键继续. . .

5.例9.5

(1)代码实现

 1 #include<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5     struct stu
 6     {
 7         long int num;
 8         char name[20];
 9         char sex;
10         float score;
11     };
12     struct stu stu_1;
13     struct stu *p;
14     p=&stu_1;
15     strcpy(stu_1.name,"Li lin");
16     stu_1.num=10101;
17     stu_1.sex='M';
18     stu_1.score=89.5;
19     printf("No:%d\nname:%s\nsex:%c\nscore:%.2f\n\n",stu_1.num,stu_1.name,stu_1.sex,stu_1.score);
20     printf("No:%d\nname:%s\nsex:%c\nscore:%.2f",(*p).num,(*p).name,(*p).sex,(*p).score);
21 }

(2)运行结果

No:10101
name:Li lin
sex:M
score:89.50No:10101
name:Li lin
sex:M
score:89.50
--------------------------------
Process exited after 0.4481 seconds with return value 0
请按任意键继续. . .

6.例9.6

(1)代码实现

 1 #include<stdio.h>
 2 #include<string.h>
 3 struct stu
 4 {
 5     long int num;
 6     char name[20];
 7     char sex;
 8     int age;
 9 };
10 struct stu a[3]{10101,"Li lin",'M',18,10102,"Zhang fang",'M',19,10104,"Wang min",'F',20};
11 int main()
12 {
13     struct stu *p;
14     printf(" No.        name     sex    age\n");
15     for(p=a;p<a+3;p++)
16     printf("%5d%13s%5c%7d\n",p->num,p->name,p->sex,p->age);
17 }

(2)运行结果

 No.        name     sex    age
10101       Li lin    M     18
10102   Zhang fang    M     19
10104     Wang min    F     20--------------------------------
Process exited after 0.1007 seconds with return value 0
请按任意键继续. . .

7.例9.7

(1)代码实现

 1 #include<stdio.h>
 2 #include<string.h>
 3 struct stu
 4 {
 5     long int num;
 6     char name[20];
 7     float score[3];
 8     float aver;
 9 };
10 struct stu a[3];
11 int main()
12 {
13     printf("请输入各学生信息:学号,姓名,三门课成绩:\n");
14     for(int i=0;i<3;i++)
15     {
16         a[i].aver=0;
17         scanf("%d%s",&a[i].num,a[i].name);
18         for(int j=0;j<3;j++)
19         {
20             scanf("%f",&a[i].score[j]);
21             a[i].aver=a[i].aver+a[i].score[j];
22         }
23         a[i].aver/=3;
24     }
25     int max=a[0].aver;
26     int count;
27     for(int i=1;i<3;i++)
28     {
29         if(a[i].aver>max){
30             max=a[i].aver;
31             count=i;
32         }
33     }
34     printf("\n成绩最高的学生是:\n");
35     printf("学号:%d\n姓名:%s\n",a[count].num,a[count].name);
36     printf("三门课成绩: ");
37     for(int i=0;i<3;i++)
38     printf("%.1f ",a[count].score[i]);
39     printf("\n平均成绩:%.2f",a[count].aver);
40 }

(2)运行结果

请输入各学生信息:学号,姓名,三门课成绩:
10101 li 78 89 98
10103 wang 98.5 87 69
10106 sun 88 76.5 89成绩最高的学生是:
学号:10101
姓名:li
三门课成绩: 78.0 89.0 98.0
平均成绩:88.33
--------------------------------
Process exited after 64.47 seconds with return value 0
请按任意键继续. . .

转载于:https://www.cnblogs.com/2016024291-/p/6681961.html

相关文章:

android button imagebutton 区别,Android 开发入门篇

Button 与 ImageButton本节学习Android基本控件按钮控件&#xff0c;Button和ImageButton用法基本类似&#xff0c;所以本节重点讲解Button控件。在布局中添加Button控件&#xff1a;android:id"id/btn"android:text"普通按钮"android:layout_width"w…

iOS autolayout 约束冲突添加symbol breakpoint

UIViewAlertForUnsatisfiableConstraints

Win7安装ant

下载ant&#xff0c;当前版本是1.9.4。下载地址点击打开链接。 解压到你喜欢的路径下面&#xff0c;我喜欢D:\Program Files\apache-ant-1.9.4 配置环境变量ANT_HOME。右击计算机→选择属性→高级系统设置→“高级”标签→环境变量。 新建系统变量。变量名必须是“ANT_HOME…

af eeee

e 转载于:https://www.cnblogs.com/xiaobaiv/p/9661043.html

ios bug 分析

ios中线上或者内部测试bug统计收集有两种方法&#xff1a; 1)使用第三方bug收集 1.bugHD 来源http://bughd.com/doc/ios-customize 2.bugtags 来源http://help.bugtags.com/hc/kb/article/124400/ http://help.bugtags.com/hc/kb/article/68482/ 3.KSCrash https://github.com/…

我理解的接口测试(一)

接口测试是测试系统组件间接口的一种测试。接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点。测试的重点是要检查数据的交换&#xff0c;传递和控制管理过程&#xff0c;以及系统间的相互逻辑依赖关系等。 接口 应用&#xff08;模块&#xff09;提供对…

android jni语法,Android NDK中的JNIEXPORT和JNICALL

基本上是一个Windows问题,如果你看看oracle Java jdk附带的文件jni_md_win32.h这是宏定义&#xff1a;/** (#)jni_md.h 1.14 03/12/19** Copyright 2004 Sun Microsystems, Inc. All rights reserved.* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.*/#ifnd…

Win7编译volley成jar包

首先安装git和ant&#xff0c;当然jdk也是必须的。 git clone搞到volley的源码。 git clone https://android.googlesource.com/platform/frameworks/volley 此时volley的目录里面应该是这样的&#xff0c;没有AndroidManifest.xml文件。 cd进volley目录&#xff0c;敲下一…

c语言的求素数算法,C语言求素数的算法

最后一次是出了素数的问题C语言解决题目(面试)&#xff0c;当时用了最粗暴的算法。回来细致參考资料&#xff0c;事实上答案有非常多种&#xff1a;1&#xff0c;小学生版本号&#xff1a;推断 x 是否为质数&#xff0c;就从 2 一直算到 x-1。static rt_uint32_t array1[ARRAY_…

Python全栈Day 15部分知识点

全局变量与局部变量 约定俗成的规则&#xff1a;全局变量名大写&#xff0c;局部变量名小写。 全局变量没有缩进&#xff0c;顶格写。 如果函数的内容无global关键字&#xff0c;优先读取局部变量&#xff0c;能读取全局变量&#xff0c;无法重新赋值&#xff0c;但是对于可变类…

SQL执行并返回执行前/后结果

SQLServer&#xff1a; 1、插入数据&#xff0c;并返回插入的数据&#xff1a;INSERT INTO TestTB(Province,City) output inserted.Province, inserted.City VALUES(广东,深圳)2、同理&#xff0c;删除数据也是一样的&#xff0c;只不过是使用deleted表罢了。delete from Test…

WebStorm 运行Rect Native 项目

今天教大家如何直接使用WebStorm这个IDE直接完成编码运行项目工作.这样就可以不用打开Xcode了. 1.首先点击WebStorm右上方的下拉箭头弹出的Edit Configurations.... 2.然后会进入一个配置页面.点击左上方的.在弹出的列表中选中npm.如图. 3.在右边的配置框中,先选择Command为hel…

Win7下用VS2010编译QGIS2.9.0

折腾了两天了&#xff0c;终于吧QGIS2.9.0在VS2010下面编译过了。 参考了许多的博客&#xff0c;在网络环境极为和&#xff08;e&#xff09;谐&#xff08;lie&#xff09;的情况下用Google查了好多资料。 其实原创的东西真的不多&#xff0c;但是毕竟是自己亲身实践得到的成…

软件工程第二次课后作业——Gaoooo

代码量&#xff1a;9行 码云仓库&#xff1a;https://gitee.com/Gaooo/2016035107059.git 实现时间&#xff1a;emmmmm&#xff08;9行代码&#xff0c;自己估计&#xff01;&#xff01;&#xff09; 程序对表达式类型的支持程度&#xff1a;全部支持&#xff01; 能支持两个操…

android检测本地是否安装,在本地测试模块的安装

Play 核心库可让您在本地测试应用是否能够执行以下操作&#xff0c;而无需连接到 Play 商店&#xff1a;请求并监控模块的安装。处理安装错误。本页介绍了如何将应用的拆分 APK 部署到测试设备&#xff0c;以便 Play 核心自动使用这些 APK 模拟从 Play 商店请求、下载和安装模块…

IsPostBack的使用

protected void Page_Load(object sender, EventArgs e){//当前用户通过Index.aspx页面中“添加用户”链接跳转到该页面时&#xff0c;这是一次get请求&#xff0c;所以不会提交表单&#xff0c;拿不到隐藏域的值。当前页面显示完成&#xff0c;用户在表单中输入数据以后单击提…

WebStorm下ReactNative代码提示设置

ReactNative 代码智能提醒 (Webstrom live template) https://github.com/virtoolswebplayer/ReactNative-LiveTemplate ReactNative的代码模板,包括: 1.组件名称 2.Api 名称 3.所有StyleSheets属性 4.React组件 安装 方法一 file -> import settings -> ReactNative.ja…

WinXp安装Oracle 11g Express Edition

由于在虚拟机上学习&#xff08;怕把真机器搞坏了&#xff09;&#xff0c;这次是在Windows XP上安装Oracle 11g Express。 本文安装的是Oracle 11g Express&#xff0c;是Oracle数据库的快速版&#xff08;学习版&#xff09;&#xff0c;安装包大小只有几百MB。 到Oracle的…

html语言书写注意事项,CSS命名规范参考及书写注意事项

CSS书写顺序*{/*显示属性*/displaypositionfloatclearcursor…/*盒模型*/marginpaddingwidthheight/*排版*/vertical-alignwhite-spacetext-decorationtext-align…/*文字*/colorfontcontent/*边框背景 为什么要把 boder和background放在最后的原因是修改的频率会较之前的频繁&…

关于移动端rem适配

var num 1 / window.devicePixelRatio; var fontSize document.documentElement.clientWidth / 10; document.getElementsByTagName(html)[0].style.fontSize fontSize px; 适配移动端rem单位&#xff0c;实际使用的时候用量取到的像素值/75即为计算后的rem值&#xff0c;标…

JavaWeb基础—JSP

一、什么是JSP JSP 全称是 Java Server Pages&#xff0c;是一种开发动态web资源的技术 在原HTML上添加JAVA脚本&#xff08;灵魂工程师&#xff0c;为页面添加灵魂&#xff09;&#xff0c;可以说 jsp html java代码 jsp标签 二、JSP的原理 JSP基本原理&#xff1a; JSP…

react-native 常用命令

创建项目 react-native init AwesomeProject //AwesomeProject是项目名启动 Node.js web server react-native start启动android react-native run-android启动ios react-native run-ios运行特定模拟器&#xff1a;react-native run-ios --simulator "iPhone 5"

使用WinPcap和libpcap类库读写pcap文件(001)开发环境配置

最近的项目要求写一个读写pcap文件的小程序&#xff0c;用来修改pcap中的部分信息&#xff0c;实现pcap的定制。 所以必须学会使用wireshark并能有利用WinPcap库和libpcap库进行开发。 虽然本文记录的都是windows下使用WinPcap进行开发&#xff0c;但是由于希望程序能够跨平台…

MySql忘记密码了咋办

对内 忘记密码终端修改操作&#xff1a; #停止mysql服务 sudo /opt/lampp/lampp stopmysql #参数启动mysqld sudo /opt/lampp/sbin/mysqld --skip-grant-tables #新建开一个终端&#xff08;复制会话&#xff09;进入 sudo /opt/lampp/bin/mysql -uroot #使用mysql权限&…

html资源文件记载进度条,用进度条显示文件读取进度《 HTML5:文件 API 》

在这个文档里&#xff0c;我添加了一个 标签 .. 上面定义了一个 ID 是 eventstatus … 我们可以把进度条放在这个容器里面 … 先找到用来显示进度条的容器 …// 找到显示事件状态的容器var eventStatus document.getElementById("eventstatus");然后再去创建进度条需…

JS中根据某个值进行大小排序

//从大到小排序 function compareBigToSmall(property){return function(a,b){var value1 a[property];var value2 b[property];return value2 - value1;} }; //从小到大排序 function compareSmallToBig(property){return function(a,b){var value1 a[property];var value…

react native 常用学习或查资料网址

react-native facebook官网&#xff1a;http://facebook.github.io/react-native/ 中文网&#xff1a;http://reactnative.cn/ react 官网地址&#xff1a;http://facebook.github.io/react/ Github地址&#xff1a;https://github.com/facebook/react 阮一峰教程&#xff1a…

使用WinPcap和libpcap类库读写pcap文件(002)PCAP文件格式

本文基本翻译自https://wiki.wireshark.org/Development/LibpcapFileFormat&#xff0c;主要分析pcap文件的格式。 其中一些字段可能和现在的WinPcap类库里的字段不同&#xff0c;请结合当前WinPcap库分析。 libpcap文件格式 libpcap文件格式是TcpDump/WinDump&#xff0c;Wir…

图论-最短路径--3、SPFA算法O(kE)

SPFA算法O(kE) 主要思想是&#xff1a; 初始时将起点加入队列。每次从队列中取出一个元素&#xff0c;并对所有与它相邻的点进行修改&#xff0c;若某个相邻的点修改成功&#xff0c;则将其入队。直到队列为空时算法结束。 这个算法&#xff0c;简单的说就是队列优化的bellman-…

如何在HHDI中进行数据质量探查并获取数据剖析报告

通过执行多种数据剖析规则&#xff0c;对目标表&#xff08;或一段SQL语句&#xff09;进行数据质量探查&#xff0c;从而得到其数据质量情况。目前支持以下几种数据剖析类型&#xff0c;分别是&#xff1a;数字值分析、值匹配检查、字符值分析、日期值分析、布尔值分析、重复值…