程序设计基础实验报告.doc

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

实验一 (3)2 读入三个整数a、b、c,交换它们中的数,使a存放b的值,b存放c的值,c存放a的值。 #includeiostream.h void main() { int a,b,c,temp; coutinput a,b,c; cinabc; temp=a; a=b; b=c; c=temp; couta b c; } (3)3 对任意输入的四位整数,分别求出其各位数字,并按从后到前的顺序依次输出。例如,输入为1234时,输出结果为4,3,2,1。 #includeiostream.h void main() { int a,b,c,d,n; coutinput number n; cinn; if(n999n10000){ a=n/1000; b=(n%1000)/100; c=(n%100)/10; d=n%10; coutdcbaendl; }else couterror; } 实验二 (2)1 求解下面函数的值。 ex+y x0,y0 z= ln(x+y) 1≤x+y〈10 log10|x+y|+1 其它情况 #includeiostream.h #includemath.h void main() { float x,y,z; coutinput 2 number; cinxy; if(x0y0){ z=exp(x+y); } if(x+y=1x+y10){ z=log(x+y); }else z=log10(fabs(x+y)+1); coutzendl; } 2 编程求解下列各计算式: 1) S= =1+2+3+…+100 #includeiostream.h void main() { int i,n,s; s=0; for(i=1;i=100;i++){ s=s+i; } coutsendl; } 2) S==1!+2!+…+7! #includeiostream.h void main() { int i,t,s; s=0; t=1; for(i=1;i=7;i++){ t=t*i; s=s+t; } coutsendl; } Y=X-+-+…+(-1)n+1+…的值,精确到10-6。 #include iostream #include cmath using namespace std; float f(int x,int n) { int s=1; for(int i=1;i=n;i++) s*=i; return pow(x,n)/s; } int main() { float x,y=0; coutenter xendl; cinx; for(int i=1;i+=2;){ y+=pow(-1,i+1)*f(x,i); if(f(x,i)1e-6) break; } coutyendl; return 0; } 3 打印下面图形。 1 1 3 1 1 3 5 3 1 1 3 5 7 5 3 1 1 3 5 7 9 7 5 3 1 … … … … … … … 1 3 … … 21 … … … 3 1 #include iostream.h #include math.h #include iomanip.h int main() { for(int i=1;i=11;i++){ for(int j=1;j=11-i;j++) cout ; for(j=1;j=2*i-1;j++) coutsetw(3)2*i-1-abs(i-j)*2; coutendl; } return 0; } 4 编程产生出1到10以内的所有数对i,j并输出,其中ij。 #includeiostr

文档评论(0)

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

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

1亿VIP精品文档

相关文档