西北工业大学动力与能源学院
上机实习报告
班 级: 02031002 专 业: 自动化 学 号: 2010301740 姓 名: 王宏业 课程名称: 上机实习 成 绩:
2012年7月4日
1.熟悉VC编程环境,用选择法对n个数字进行排序。 程序编制要点(知识点、程序框图):
开始 输入数字个数n和需要排序的数字 j=0 N j
源程序代码:
#include
using namespace std; int main() {
int i,j; double tmp; double a[n];
for (i=0;i
for(j=n-1;j>0;j--) for(i=0;i if (a[i] tmp=a[i+1];a[i+1]=a[i];a[i]=tmp; } } for (i=0;i 程序执行结果(拷屏): 源程序文件名: 第一天第一题.cpp 1.利用梯形法计算?sinxdx,?cosxdx,?exdx。 0?10113程序编制要点(知识点、程序框图): 开始 定义变量 用梯形法计算 N 满足精度 Y 输出结果 结束 源程序代码: 1?0sinxdx的源程序 #include using namespace std; double f(double x) { return sin (x); } int main() { double a,b,h,k,l,s; int i; long n=10000; cout << \请输入要积分sin的上下限\ cin >> a >> b; if (a>b) } k=a,a=b,b=k; h=(b-a)/n; for (i=1,s=f(a)+f(b);i cout << l << endl; return 0; ?1?1cosxdx的源程序 #include using namespace std; #define e 1e-6 #define f(x) (cos(x)) int main() { int i,n,a,b,k; double h,ll,l,g; n=1; cout << \请输入要积分cos x的上下限\ cin >> a >> b; if (a>b) k=a,a=b,b=k; //判断输入的数值是否是上下限 h=(double)(b-a)/2; l=h*(f(a)+f(b)); do { ll=l; g=0; for (i=1;i<=n;i++) g+=f((a+(2*i-1)*h)); l=(ll/2)+(h*g); n*=2; h/=2; } while (fabs(l-ll)>e); cout< return 0; } ?30edx的源程序 x#include