(三) 实验步骤及结果
1.表达式求值的程序验证的实验步骤及结果
表2.1 表达式值的计算
结果正确!
2.源程序修改、替换的实验步骤及结果
(1)改错:headp类型应为双重指针,即:void creat_list(struct s_list **headp, int *p); 同时第40行应该改为*headp = loc_head; 第12行改为creat_list(&head, s); 修改后的程序如下: #include#includestruct s_list{ int data;
struct s_list *next; };
void creat_list(struct s_list **headp, int *p); int main(void)
{
struct s_list *head = NULL, *p; int s[] = {1, 2, 3, 4, 5, 6, 7, 8, 0}; creat_list(&head, s); p = head; while(p) {
printf("%d ", p -> data);p = p -> next; }
printf(" "); return 0; }
void creat_list(struct s_list **headp, int *p) {
struct s_list *loc_head = NULL, *tail; if(p[0] == 0); else {
loc_head = (struct s_list *)malloc(sizeof(struct s_list));loc_head -> data = *p++;tail = loc_head;while(*p){
tail -> next = (struct s_list *)malloc(sizeof(struct s_list)); tail = tail -> next; tail -> data = *p++;}
tail -> next = NULL; }
*headp = loc_head; }
程序运行结果如图所示:
结果正确!
(2)建立一个后进先出的链表如下:
修改后程序如下: #include#includestruct s_list{ int data;
struct s_list *next; };
void creat_list(struct s_list **headp, int *p); int main(void) {
struct s_list *head = NULL, *p; int s[] = {1, 2, 3, 4, 5, 6, 7, 8, 0}; creat_list(&head, s); p = head; while(p) {
printf("%d ", p -> data);p = p -> next; }
printf(" "); return 0; }
void creat_list(struct s_list **headp, int *p) {
struct s_list * loc_head=NULL,*tail; struct s_list * temp; if(p[0]==0) ; 篇三:C语言程序设计上机实验报告
一、实验目的:
1.熟悉Win TC或者VC++ 6.0的软件环境,掌握使用其进行编辑、编译、连接和运行的方法。 2.通过运行简单的C程序,掌握C源程序的特点。
二、实验内容:(由学生选择WinTC或者VC之一完成相关实验) 1.运行WinTC程序,进入C程序设计环境。 2.建立工程文件 3.编辑源文件 4.编译、连接
(1)单文件源程序的编译、连接
源程序先经过编译,生成目标文件(.obj文件),然后将目标文件进行连接,生成可执行文件(.exe)。 如果编译、连接中发生错误,在Message窗口中显示出错信息,修改错误后,可重新编译、连接。 (2)多文件源程序的编译、连接
可以用长的源程序分割成几个文件,分别编译然后生成可执行文件。此时使用Project菜单。步骤: 第一步:有三个文件f1.c、f2.c、f3.c组成一个完整的C程序,分别建立三个文件,将f1.c、f2.c、f3.c三个文件保存到同一个文件夹中(如d: cproject)。 f1.c:
#include "stdio.h" extern a,b;
extern max(int x,int y); main() { int e
=1,f=2;
printf("%d ",max(a,b)); printf("%d ",max(e,f)); } f2.c: int a=3,b=4; f3.c:
int max(int x,int y ) {return x>yx:y;}
第二步:构造Project文件,在编辑状态下,编辑一个扩展名为.prj的文件,文件的内容为:
f1 f2 f3
第三步:构造EXE文件,按F9键即将三个文件编译、连接成一个EXE文件,文件名为wang.exe。 如果编译、连接出现错误,则必须进行修正,然后再编译。 5.运行程序
如果编译、连接完全正确,则可以用运行程序。
三、实验过程(依据上面示例,简要描述你使用WinTC或者其它编译器的过程)
【c语言程序设计实验报告模板】相关文章:
3.电机实验报告模板
4.实验报告模板
7.科技实验报告模板
本文来源:http://www.010zaixian.com/gongwen/gongzuojihua/2758531.htm