C语言实验报告

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
6 指针实验......................................................................................................................................79 6.1 必做题..............................................................................................................................79 6.2 小结..................................................................................................................................99
scanf_s("%d", &f);
//格式错误,加&
c = (double)5 / 9 * (f - 32);
//类型不同,加 double
printf("\n %d(F)=%.2f(C)\n\n", f, c);
2 流程控制实验..............................................................................................................................11 2.1 必做题...............................................................................................................................11 2.2 小结..................................................................................................................................25
5 数组实验......................................................................................................................................58 5.1 必做题..............................................................................................................................58 5.2 选做题..............................................................................................................................76 5.3 自设题..............................................................................................................................78 5.4 小结..................................................................................................................................78
8 文件实验....................................................................................................................................115 8.1 必做题............................................................................................................................ 115 8.2 小结................................................................................................................................123
7 结构与联合实验........................................................................................................................100 7.1 必做题............................................................................................................................100 7.2 小结................................................................................................................................114
}
(b) 分析错误并修正
#include <stdio.h>
#define PI 3.14159
//去掉分号
void main(void)
//添加空格
{
int f;
short p, k;
double c, r, s;
/*for task 1*/
printf("Input Fashrenheit:");
4 编译预处理实验..........................................................................................................................44 4.1 必做题..............................................................................................................................44 4.2 自设题..............................................................................................................................55 4.3 小结..................................................................................................................................57
2
1 表达式和标准输入输出实验
1.1 必做题
1.1.1 程序改错:
(a)题目 下面给出了一个简单 C 语言程序例程,用来完成以下工作:
1) 输入华氏温度 f,将它转换成摄氏温度 c 后输出; 2) 输入圆的半径值 r,计算并输出圆的面积 s; 3) 输入短整数 k、p,将 k 的高字节作为结果的低字节,p 的高字节作 为结果的高字节,拼成一个新的整数,然后输出; 在这个例子程序中存在若干语法和逻辑错误。要求在计算机上对这个例子程 序进行调试修改,使之能够正确完成指定任务。 #include<stdio.h> #define PI 3.14159; voidmain( void ) { int f ; short p, k ; double c , r , s ; /* for task 1 */ printf(“Input Fahrenheit:” ) ; scanf(“%d”, f ) ; c = 5/9*(f-32) ; printf( “ \n %d (F) = %.2f (C)\n\n ”, f, c ) ; /* for task 2 */ printf("input the radius r:"); scanf("%f", &r); s = PI * r * r;
课程实验报告
课程名称:
C 语言程序设计
专业班级: 计算机科学与技术 学 号: 姓 名: 指导教师: 报告日期:
1
计算机科学与技术学院
目录
1 表达式和标准输入输出实验........................................................................................................3 1.1 必做题................................................................................................................................3 1.2 小结..................................................................................................................................10
3 函数与程序结构实验..................................................................................................................26 3.1 必做题..............................................................................................................................26 3.2 选做题..............................................................................................................................39 3.3 自设题..............................................................................................................................41 3.4 小结..................................................................................................................................42
3
printf("\nThe acreage is %.2f\n\n",&s);
/* for task 3 */
printf("input hex int k, p :");
scanf("%x %x", &k, &p );
newint = (p&0xff00)|(k&0xff00)<<8;
Baidu Nhomakorabea
printf("new int = %x\n\n",newint);
相关文档
最新文档