C program test report
Name: Huang Jing micro-experiment time: February 25
experimental project:
1, calculated with the product of two integers
2, the output of program editing simple pattern
3, the output of the data size of the program editor
4, expression is evaluated
5, the expression of the application
1, experimental purposes and requirements:
1, and calculate the product of two numbers
Learning writing arithmetic expressions
Learn printf () function of the basic usage
Familiar scanf () function of the basic usage
2, the output of program editing simple pattern
Learn C under Dev C ++ language program development environment
Using simple C program, a preliminary understanding of the characteristics of the C language source code
3, the output of the data size of the program editor
Learn the sizeof operator specific usage
Using simple C program, a preliminary understanding of the characteristics of the C language source code
4, expression is evaluated
Way to learn the definition of variables
Familiar with scanf () input data
Familiar with printf () value of the output variables
Mastering operators and expressions
5, the expression of the application
Learning C language representation of expression
Correctly defined variable in the program
Proper use scanf () provided by the user input data
Proper use print () output variables
Second, the experimental content
1, lab exercises: 1.3.2
Problem Description: Write a program to calculate sum and product of two integers.
Experiment code:
#include <stdio.h> main() { int a,b,c,d; printf("Please enter a,b:"); scanf("%d,%d",&a,&b); c=a+b; d=a*b; printf("%d+%d=%d",a,b,c); printf("%d*%d=%d",a,b,d); }
Question: character converting data types
Solution:% d output by the address character & achieve
2, exercises: 1.3.3
Problem Description: Write a program right triangle, composed of the output from the *.
Experiment code:
#include <stdio.h> main() { printf("*\n"); printf("**\n"); printf("***\n"); printf("****\n"); printf("*****\n"); }
Question: How can output a regular geometric patterns
The solution: use printf statement progressive pattern output
3, lab exercises: 1.3.4
Problem Description: programming, the output size of each data type in C language storage space.
Experiment code:
#include <stdio.h> main() { printf("Data Types and Sizes:\n"); printf("long:%d\n",sizeof(long)); printf("unsigned int:%d\n",sizeof(unsigned int)); printf("double:%d\n",sizeof(double)); }
问题:用什么函数将数据类型所占用的存储空间大小输出。
解决办法:使用系统提供的求某种数据类型存储空间字节数的函数sizeof( )
4、实验练习:2.3.1
问题描述:计算表达式的值
实验代码:
#include <stdio.h> #include <math.h> main() { float a,b,c; printf("Please enter a,b:"); scanf("%f,%f",&a,&b); c=(b+sqrt(b*b+2*a))/(a-b); printf("c=%.2f\n",c); }
问题:表达式的C语言表达式
解决办法:(b+sqrt(b*b+2*a))/(a-b)
5、实验练习:2.3.2
问题描述:从键盘输入圆锥体的半径r和高度h,并计算其底面积和体积。
实验代码:
#include <stdio.h> #include <stdio.h> main() { float r,h,s,v; printf("Please input r,h:"); scanf("%f,%f",&r,&h); v=3.14*r*r*h/3; s=r*r*3.14; printf("体积=%.2f\n",v); printf("表面积=%.2f\n",s); }
问题:数据类型的确定,圆锥体底面积和体积的计算表达式
解决办法:采用float和double定义变量,s=r×r×3.14,v=r×r×3.14×h/3
三、实验小结
本次实验课共进行了五个实验,第一次用Dev C++编写程序,由于缺少实践操作,对编写程序不是很熟悉,速度也比较慢,但通过此次实验课,我学习到了基本的程序调试过程,通过运行简单的C语言程序,初步了解了C语言源程序的特点,对表达式中的数据类型有了更准确的判断,对printf()输出变量与scanf()输入数据的用法也更加熟悉。同时,在本次实验课中,也出现了不少的问题, 有时输入代码出错,导致程序编译是出现问题,程序无法运行,希望在后续的学习中能更加熟练。