C语言课程实验

实验课基本要求

实验运行环境简介

C++集成开发环境

如果机房电脑速度太慢参看温大机房优化脚本

实验1-1

1. 实验目的

熟悉C语言开发环境,学会

2. 实验内容

编译运行以下程序,观察程序运行的结果 完成课后作业1-1

   1 #include <stdio.h>
   2 main() 
   3 {
   4         printf("hello, world\n");
   5 }

   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 #include <stdio.h>
   2 /* print Fahrenheit-Celsius table*/
   3 main()
   4 {
   5     int fahr;
   6 
   7     for (fahr = 0; fahr <= 300; fahr = fahr + 20)
   8         printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
   9 }

{{{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. 实验目的

2. 实验内容

完成课后作业1-4,1-5

实验1-3

1. 实验名称

函数的编写

2. 实验目的

3. 实验内容

完成课后作业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. 实验目的

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. 实验内容

写一个程序,输入一组整数,计算它们的平均值。 例如:输入

C语言课程实验 (2008-02-23 15:36:56由localhost编辑)