19975
备注:
|
20391
|
删除的内容标记成这样。 | 加入的内容标记成这样。 |
行号 208: | 行号 208: |
= 实验1-10 = == 实验内容 == 写一个程序,输入一组整数,计算它们的平均值。 例如:输入 {{{100 80 60 40}}} 输出 {{{70 }}} 提示:调用getint实现 = 实验1-11 = == 实验内容 == 用指针的方式实现课后练习4-1: Write the function strrindex(s,t), which returns the position of the rightmost occurrence of t in s, or -1 if there is none. |
|
行号 228: | 行号 249: |
for(j = tlen; j >= i; j--) | for(j = slen; j >= i; j--) |
实验课基本要求
- 实验课前对实验内容做好预习
- 有效利用实验课时间,不做与实验无关的活动
- 独立完成实验内容
- 按时提交实验报告
实验运行环境简介
1. DEV-C++集成开发环境
安装运行
- 运行安装程序进行安装
- 运行集成开发环境:开始菜单=〉Bloodshed Dev-C++ =〉Dev-C++
工程创建
在Dev-C++菜单中选择File=>New=>Project
- 在弹出对话框中选择Console Application,选中C Project,Name框输入一个工程名字,最后按OK按钮
- 选择硬盘上某个路径保存你所建立的工程
程序运行
选择菜单Execute=>Compile编译程序
如果编译没有错误,选择Execute=>Run运行程序,得到运行结果
如果程序结果一闪而过,怎么办?
- 在命令行窗口中运行可执行程序
- 在代码中添加:system("PAUSE");一行使程序暂停(system函数在stdlib.h中定义)
调试程序
- 启动调试
选择菜单Debug=>Debug
- 设置断点
将光标移动到需要设置断点的行,选择Debug=>Toggle Breakpoint
- 单步执行
菜单Debug=>Next Step和Step Into
- 查看变量
菜单Debug=>Add Watch
2. Visual Studio.Net 2003集成开发环境
创建工程
- 打开Visual Studio.net 2003集成开发环境
菜单File=>New=>Project
- 在弹出的对话框中:Project Types选择Visual C++ Projects,Templates选择Win32 Console Application,Name中输入工程名称,Location选择保存的路径。最后点OK
- 在接下来的工程向导中,选择Application Settings,选择Empty Project,最后按Finish
菜单View=>Solution Explorer
- 在Solution Explorer中选中刚才建立的工程
菜单File=>Add New Item
- 在弹出的对话框中:Categories选择Visual C++,Templates选择C++ File,Name中输入文件名,文件要以.c结尾,最后按Open。
编译运行
菜单Build=>Build Solution
如果编译通过,选择菜单Debug=>Start Without Debugging
调试
开始调试:菜单Debug=>Start
- 设置断点:光标移动到要设置断点的地方,按F9
- 单步执行:Debug菜单下的Step Into和Step Over
- 查看变量:Debug菜单下的Quick Watch
实验1-1
1. 实验目的
熟悉C语言开发环境,学会
- 创建工程
- 编辑代码
- 编译连接,生成可执行程序
- 调试代码
2. 实验内容
编译运行以下程序,观察程序运行的结果 完成课后作业1-1
1 #include <stdio.h>
2 /* print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300 */
3 main ()
4 {
5 int fahr, celsius;
6 int lower, upper, step;
7 lower = 0;
8 upper = 300;
9 step = 20;
10 fahr = lower;
11 while ( fahr <= upper) {
12 celsius = 5 * (fahr - 32) / 9;
13 printf( "%d\t%d\n", fahr, celsius);
14 fahr = fahr + step;
15 }
16 }
{{{1-1 Run the "hello, world" program on your system. Experiment with leaving out parts of the program, to see what error messages you get. }}}
实验1-2
1. 实验目的
- 掌握C语言变量、循环的基本概念
- 掌握基本的算术运算
2. 实验内容
完成课后作业1-4,1-5
- Write a program to print the corresponding Celsius to Fahrenheit table.
- Modify the temperature conversion program to print the table in reverse order, that is, from 300 degrees to 0.
实验1-3
1. 实验目的
- 掌握C语言函数的基本概念
- 掌握C语言函数的定义和调用方法
- 理解C语言字符串和字符数组的使用方法
2. 实验内容
完成课后作业1-17: Write a program to print all lines that are longer than 80 characters.
实验1-4
1. 实验目的
掌握位运算符的基本用法
2. 实验内容
完成课后习题2-8: Write a function rightrot(x,n) that returns the value of the integer x rotated to the right by n positions.
实验1-5
1. 实验目的
- 掌握关系表达式和IF语句
- 掌握循环的使用方法
- 巩固C语言数组、字符串的使用方法
2. 实验内容
练习1-19
Write a function reverse(s) that reverses the character string s. Use it to write a program that reverses its input a line at a time.
实验1-6
1. 实验目的
2. 实验内容
Write a version of itoa that accepts three arguments instead of two. The third argument is a minimum field width; the converted number must be padded with banks on the left if necessary to make it wide enough.
实验1-7
1. 实验目的
- 掌握全局变量使用方法
- 掌握多文件的组织方法
2. 实验内容
Exercise 4-3. Given the basic framework, it's straightforward to extend the calculator. Add the modulus (%) operator.
实验1-8
1. 实验目的
掌握递归函数的编写方法
2. 实验内容
Write a recursive version of the function reverse(s), which reverses the string s in place.
实验1-9
1. 实验内容
书中给定了栈的数据结构和两个操作函数(push,pop),请在此基础上添加 {{{top函数:取栈顶元素 empty函数:判断栈是否为空,栈非空返回0,栈为空返回非零 size函数:返回栈中元素的个数 clear函数:清空栈 print函数:打印栈中每一个元素}}} 添加这些函数后,使以下main函数能够正确运行:
1 main()
2 {
3 push(1);
4 push(2);
5 push(3);
6 printf("size:%d\n", size() );
7 printf("top:%f\n", top() );
8 printf("stack is%s empty\n", (empty() ?"":" not" ));
9 printf("content: ");
10 print();
11 printf("\n");
12 clear();
13 printf("size:%d\n", size());
14 printf("stack is%s empty\n", (empty() ?"":" not" ));
15 }
正确的输出应该为: {{{size:3 top:3 stack is not empty content: 1 2 3 size:0 stack is empty }}}
实验1-10
1. 实验内容
写一个程序,输入一组整数,计算它们的平均值。 例如:输入