C程序设计实验报告
实验项目:C语言程序设计实验报告
姓名:周曼洁 实验地点:家 实验时间:2020.03.01
一.实验目的与要求
1.实验目的
(1)掌握DVEC++的安装方法,并学会运用这个编程软件
(2)运行简单的C语言程序,并了解C语言的简单结构
(3)掌握C语言基本类型及使用方法
(4)熟悉C语言运算符和表达式的使用
2.实验要求
二.实验内容
1.实验练习1.3.2
1问题的简单描述:运行时得不到所要的结果
2实验代码:
#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); }
3问题分析:输入法错误,中文输入法运行时多出一个空格,应使用英文输入法
2.实验练习1.3.3
1问题的简单分析:无
2实验代码:
#include <stdio.h>
main()
{
printf("*\n");
printf("**\n");
printf("***\n");
printf("****\n");
printf("*****\n");
}
3问题分析:无
3.实验练习1.3.4
1简单的问题描述:主要是sizeof的应用
2实验代码:
#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));
3问题分析:sizeof运算符的特殊用法需要注意
4.实验练习2.3.1
1问题的简单描述:math头文件的使用
2实验代码:
#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); }
3问题分析:不能丢失头文件
5.实验练习2.3.2
1问题的简单描述:
2实验代码:
#include<stdio.h> #include<math.h> main() { float r,h,s,v; printf("Please input r,h:\n"); scanf("%f,%f",&r,&h); s=3.14*r*r; v=3.14*r*r*h/3; printf("底面积=%.2f 体积=%.2f",s,v); }
3问题分析:需要先定义变量float,n的使用
三.实验小结
第一次写实验报告,也是第一次写代码。在这次实验中,我体会到在写代码的过程中需要特别注意细节,一点点小差错就会导致运行错误。而在C语言的学习中,更应该动手操作,很多错误只有犯过才会印象深刻。希望以后在C语言的学习中能够越来越好。