当前位置:文档之家› C语言实验报告

C语言实验报告

6 指针实验......................................................................................................................................79 6.1 必做题..............................................................................................................................79 6.2 小结..................................................................................................................................99
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;
printf("new int = %x\n\n",newint);
课程实验报告
课程名称:
C 语言程序设计
专业班级: 计算机科学与技术 学 号: 姓 名: 指导教师: 报告日期:
1
计算机科学与技术学院
目录
1 表达式和标准输入输出实验........................................................................................................3 1.1 必做题................................................................................................................................3 1.2 小结..................................................................................................................................10
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:");
scanf_s("%d", &f);
//格式错误,加&
c = (double)5 / 9 * (f - 32);
//类型不同,加 double
printf("\n %d(F)=%.2f(C)\n\n", f, c);
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;
2 流程控制实验..............................................................................................................................11 2.1 必做题...............................................................................................................................11 2.2 小结..................................................................................................................................25
3 函数与程序结构实验..................................................................................................................26 3.1 必做题..............................................................................................................................26 3.2 选做题..............................................................................................................................39 3.3 自设题..............................................................................................................................41 3.4 小结..................................................................................................................................42
相关主题