网站大量收购独家精品文档,联系QQ:2885784924

[工学]C语言实验报告.doc

  1. 1、本文档共7页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
[工学]C语言实验报告

实验一 顺序结构: #include(math.h) #include(stdio.h) main() {double x,y; printf(please enter x:) scanf(%f,x); y=3.0/4*pow(x,5)+12*pow(x,4)-7.3*pow(x,3)-8.0/3*pow(x,2)+2*x-4 printf(\ny=%lf,y); } 任意输入一个三位数,然后逆序输出,要有输入数据的提示语句。 #includestdio.h #includemath.h main() { int x,a,b,c,m; printf(\n please enter a number x:); scanf(%d,x); a=x/100;b=x%100/10;c=x%10; m=c*100+b*10+a; printf(\n after exchanging:%d\n,m); } 用八进制的形式输出个位数的ASCII码。 #includestdio.h #includemath.h main() { int x,a,b,c,m; printf(\n please enter a number x:); scanf(%d,x); a=x/100+0;b=x%100/10+0;c=x%10+0; m=c*100+b*10+a+0; printf(\n 交换后各位数的八进制ASCII码:%o,%o,%o,%o\n,c,b,a,m); } 实验2 #includestdio.h #includemath.h main() {double y,x; int i=1; printf(\n请输入变量x:); scanf(%lf,x); if(x-1||x=2) i=0; if(-1=xx0) y=4*x-8; else if(0=xx1) y=3*pow(x,2)+10*x-1; else if(1=xx2) y=8*pow(x,3)-3*x*x+2*x-1; if(!i) printf(\n data error); else printf(\ny=%lf\n,y); } #includestdio.h main() {int i,j=1; double m,x,y; printf(\n请输入苹果等级、数量和所付款:); scanf(%lf%lf%lf,i,m,x); switch(i) {case 1: y=5.5*m;break; case 2:y=4.2*m;break; case 3:y=3.0*m; case 4: y=2.5*m; default:j=0; } if(j)printf(应付钱:y=%.2lf找零:x-y=%lf\n,y,x-y); if(m0||xy||j==0) printf(data error\n); } 单层循环计算1!+2!+3!+4!+5! #includestdio.h main() { int k; long s,t; s=0;t=1; for(k=1;k=5;k++) { t=t*k; s=s+t;} printf(\ns=%ld,s); } 双层循环 #includestdio.h void main() { int i,j,t; long int s=0; for(i=1;i=5;i++) {t=1; for(j=1;j=i;j++) t*=j; s+=t; } printf(\n%ld,s); } 定义一个有10个元素的一维数组count,从键盘上输入8个整数,将其按从大到小的顺序排列,并将排列 后的数组输出。1》做出流程图 2)用数组的方法编写程序 3)用指针的方法编写程序。 #includestdio.h main() { int a[10],i,j,t; for(i=0;i8;i++) scanf(%d,a[i]); for(i=0;i8;i++) { for(j=i+1;j8;j++) {if(a[j]a[i]) {t=a[i];a[i]=a[j];a[j]=t;} continue;} } for(i=0;i8;i++) printf(%8d,a[i]); } 输入2个字符串,将这两个字符串连接起来并输出,再将连接后的字符串反向。 1)分别输出连接后的字符串和反向后的字符串,并求连接后字符串的长度。 #includestring.h #includestdio.h void main() {int i,j,len; char a1[10],a2[5],a3[10]; printf(输入数组a1中的五个元素:); gets(a1); printf(输入数组a2中的五个元素:); gets(a2); strca

文档评论(0)

ctuorn0371 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档