翁恺c语言程序设计入门答案

时间: 2023-11-19 14:04:14 浏览: 44
翁恺是一位著名的计算机科学家,他的《C语言程序设计入门》是一本非常经典的C语言入门教材。这本书主要介绍了C语言的基础语法、数据类型、运算符、流程控制语句、函数、数组、指针等内容。下面是两个与题目相关的例子: 引用: ```c int i,x,y; i=x=y=0; do { ++i; if ( i%2 ) x+=i, i++; y +=i++; } while ( i<=7 );printf("%d %d %d", i, x, y); // 输出:10 24 64 ``` 该代码的输出结果为10 24 64。代码中定义了三个整型变量i、x、y,并将它们都初始化为0。然后使用do-while循环,循环条件为i<=7。在循环体中,首先对i进行自增操作,然后判断i是否为奇数,如果是,则将i加到x中,然后再将i自增1;否则直接将i自增1。最后将i加到y中,然后再将i自增1。循环结束后,输出i、x、y的值。 引用: ```c #include <stdio.h> int main(){ int j=4; for ( int i=4; i<=8; i++ ) { switch ( i/4 ) { case 0: case 1: printf("*"); break; case 2: printf("#"); } } return 0; } // 输出:***## ``` 该代码的输出结果为***##。代码中定义了两个整型变量i、j,并将j初始化为4。然后使用for循环,循环条件为i<=8,每次循环i自增1。在循环体中,使用switch语句根据i/4的值来判断输出*还是#。当i/4的值为0或1时,输出*;当i/4的值为2时,输出#。循环结束后,返回0。

相关推荐

7-3 Score Processing 分数 10 作者 翁恺 单位 浙江大学 Write a program to process students score data. The input of your program has lines of text, in one of the two formats: Student's name and student id, as <student id>, <name>, and Score for one student of one course, as <student id>, <course name>, <marks>. Example of the two formats are: 3190101234, Zhang San 3190101111, Linear Algebra, 89.5 Comma is used as the seperator of each field, and will never be in any of the fields. Notice that there are more than one word for name of the person and name of the course. To make your code easier, the score can be treated as double. The number of the students and the number of the courses are not known at the beginning. The number of lines are not known at the beginning either. The lines of different format appear in no order. One student may not get enrolled in every course. Your program should read every line in and print out a table of summary in .csv format. The first line of the output is the table head, consists fields like this: student id, name, <course name 1>, <course name 2>, ..., average where the course names are all the courses read, in alphabet order. There should be one space after each comma. Then each line of the output is data for one student, in the ascended order of their student id, with score of each course, like: 3190101234, Zhang San, 85.0, , 89.5, , , 87.3 For the course that hasn't been enrolled, leave a blank before the comma, and should not get included in the average. The average has one decimal place. There should be one space after each comma. And the last line of the output is a summary line for average score of every course, like: , , 76.2, 87.4, , , 76.8 All the number output, including the averages have one decimal place. Input Format As described in the text above. Output Format As described in the text above. The standard output is generated by a program compiled by gcc, that the round of the first decimal place is in the "gcc way". Sample Input 3180111435, Operating System, 34.5 3180111430, Linear Algebra, 80 3180111435, Jessie Zhao 3180111430, Zhiwen Yang 3180111430, Computer Architecture, 46.5 3180111434, Linear Algebra, 61.5 3180111434, Anna Teng Sample Output student id, name, Computer Architecture, Linear Algebra, Operating System, average 3180111430, Zhiwen Yang, 46.5, 80.0, , 63.2 3180111434, Anna Teng, , 61.5, , 61.5 3180111435, Jessie Zhao, , , 34.5, 34.5 , , 46.5, 70.8, 34.

最新推荐

recommend-type

浙大C语言课件 ppt

这是浙江大学C语言 老师上课用的课件 英文版 这是浙江大学C语言 老师上课用的课件 英文版 讲的很仔细
recommend-type

YOLOv8中加入CBAM注意力机制

YOLOv8中加入CBAM注意力机制,适合目标检测方向新手小白对YOLOv8作出改进,开箱即用,上传不易,小伙伴拿走的同时请顺手一键三连哈
recommend-type

高分项目 基于STM32单片机的语音导盲系统设计源代码+原理图+项目资料齐全+教程文档.zip

【资源概览】 高分项目 基于STM32单片机的语音导盲系统设计源代码+原理图+项目资料齐全+教程文档.zip高分项目 基于STM32单片机的语音导盲系统设计源代码+原理图+项目资料齐全+教程文档.zip高分项目 基于STM32单片机的语音导盲系统设计源代码+原理图+项目资料齐全+教程文档.zip 【资源说明】 高分项目源码:此资源是在校高分项目的完整源代码,经过导师的悉心指导与认可,答辩评审得分高达95分,项目的质量与深度有保障。 测试运行成功:所有的项目代码在上传前都经过了严格的测试,确保在功能上完全符合预期,您可以放心下载并使用。 适用人群广泛:该项目不仅适合计算机相关专业(如电子信息、物联网、通信工程、自动化等)的在校学生和老师,还可以作为毕业设计、课程设计、作业或项目初期立项的演示材料。对于希望进阶学习的小白来说,同样是一个极佳的学习资源。 代码灵活性高:如果您具备一定的编程基础,可以在此代码基础上进行个性化的修改,以实现更多功能。当然,直接用于毕业设计、课程设计或作业也是完全可行的。 欢迎下载,与我一起交流学习,共同进步!
recommend-type

HTML+CSS+JS精品网页模板H78.rar

HTML+CSS+JS精品网页模板,设置导航条、轮翻效果,鼠标滑动效果,自动弹窗,点击事件、链接等功能;适用于大学生期末大作业或公司网页的设计制作。响应式网页,可以根据不同的设备屏幕大小自动调整页面布局; 支持如Dreamweaver、HBuilder、Text 、Vscode 等任意html编辑软件进行编辑修改; 支持包括IE、Firefox、Chrome、Safari主流浏览器浏览; 下载文件解压缩,用Dreamweaver、HBuilder、Text 、Vscode 等任意html编辑软件打开,只需更改源代码中的文字和图片可直接使用。图片的命名和格式需要与原图片的名字和格式一致,其他的无需更改。如碰到HTML5+CSS+JS等专业技术问题,以及需要对应行业的模板等相关源码、模板、资料、教程等,随时联系博主咨询。 网页设计和制作、大学生网页课程设计、期末大作业、毕业设计、网页模板,网页成品源代码等,5000+套Web案例源码,主题涵盖各行各业,关注作者联系获取更多源码; 更多优质网页博文、网页模板移步查阅我的CSDN主页:angella.blog.csdn.net。
recommend-type

PVG800S-800mm皮带检测报告(TABG-ZXJ 2021-069).pdf

PVG800S-800mm皮带检测报告(TABG-ZXJ 2021-069).pdf
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

如何用python编写api接口

在Python中编写API接口可以使用多种框架,其中比较流行的有Flask和Django。这里以Flask框架为例,简单介绍如何编写API接口。 1. 安装Flask框架 使用pip命令安装Flask框架: ``` pip install flask ``` 2. 编写API接口 创建一个Python文件,例如app.py,编写以下代码: ```python from flask import Flask, jsonify app = Flask(__name__) @app.route('/api/hello', methods=['GET']) def hello():
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。