ImageVerifierCode 换一换
格式:DOCX , 页数:89 ,大小:40.96KB ,
资源ID:17097792      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/17097792.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(皮德常c++全套答案Word文档下载推荐.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

皮德常c++全套答案Word文档下载推荐.docx

1、2-7、用for循环计算1/302/29+3/28+30/1。 int i; float sum=0; for(i=1;=30;i+) sum+=i/float(31-i);sum=sum;2-8、用循环语句输出如下图形。AAAAAAA AAAAA AAA A int i,j,k; for(i=0;=3;i+) /控制行 for(j=0;jk-) /控制每行输出的A for(j=3;jj-) for(k=0;kan;=n; temp=a+temp*10; sum+=temp;the result is :2-11、输入一行字符,以回车结束,分别统计其中出现的大写英文字母、小写英文字母、数字字符

2、、空格和其他字符出现的次数。 char c; int lletters=0,uletters=0,spaces=0,digits=0,others=0;Please enter the characters:n while(c=cin.get()!=n) if(ca&cZ uletters+; else if(c= spaces+; else if(c09 digits+; else others+;the number of lower case letters:llettersthe number of upper case letters:ulettersthe number of di

3、gits:digitsthe number of spaces:spacesk;the combination number of n and k:comb(n,k);3-2、编写函数计算ex的近似值,在主函数中输入x及精度10-9(要求最后一项小于10-9)。cmathdouble ex(double x,double eps) int i=1; double e=1,t=1; while(fabs(t)eps) t=t*x/i; e=e+t; i+; return(e); double x,eps;Please inout x and eps:xeps;e*x:ex(x,eps);3-3、

4、编写被调函数,求出1000以内 素数,在主函数中调用函数并输出素数,每行输出5个素数。iomanipvoid PrimeNum(int n=1000) int i, j, k, flg=1, num=0; for(i=2; k=sqrt(i); for(j=2;=k; if(i%j=0) flg=0; if(flg=1) coutsetw(5) num+; if(num%5=0) cout flg=1; PrimeNum();3-4、输出1000以内的所有完数。void print(int n) /输出因子=n/2; if(n%i=0) coutvoid wanshu(int n) int a

5、,s=0; a=n/2;=a; if(n%i=0) s+=i; if(s=n) coutn its factors are: print(n);=1000; wanshu(i);3-5、编写函数(递归和非递归)求两个整数的最大公约数和最小公倍数。int gcd(int x,int y) int r; r=x%y; while (r!=0) x=y; y=r; return(y);/int gcd(int a, int b)/ if(a%b=0) / return b; /else / return gcd(b, a%b);/int gbs(int x,int y) int bs,ys; ys=

6、gcd(x,y); bs=x*y/ys; return bs; int x,y,g,bs;Enter two number: n y; g=gcd(x,y); bs=gbs(x,y);the gcd:g0)x%10; rev(x/10); int x;Please input an integer:x;reverse: if(x 1) fun(i/2);i%2;void main() int n;Please input the decimal number:the binary number: fun(n);3-9、编写函数输出图形。(略)3-10、编写min函数模板和max函数模板。#in

7、clude templateT min(T &var1,T &var2) if(var1userInt2;the min is:min(userInt1,userInt2)the max is:max(userInt1,userInt2)userFloat2;min(userFloat1,userFloat2)max(userFloat1,userFloat2)userChar2;min(userChar1,userChar2)max(userChar1,userChar2)3-11、绝对值函数模板。T Abs(const T var) if(var return(-var); return(

8、var); /测试整型量求绝对值 int test1=12,test2=-34;测试整型量:test1=test1ttest1的绝对值为:Abs(test1)test2=test2ttest2的绝对值为:Abs(test2) /测试浮点型量求绝对值 float test3=12.67f,test4=-34.43f;测试浮点型量:test3=test3ttest3的绝对值为:Abs(test3)test4=test4ttest4的绝对值为:Abs(test4)max) max=arrayi; maxid=i; if(arrayimin) min=arrayi; minid=i;the max o

9、f the array is maxthe index of the max is maxidthe min of the array is minthe index of the min is minidstri stri-=32; ch = stri; char str100;Please input a string: cin.getline(str,100); Words(str);str;4-4、编程实现线性查找账号,账号由用户输入,若找到,则输出合法信息,否则输出非法信息。#define arrSize 5int searchList(int list , int numElems

10、, int value) for(int i=0; i numElems; if( value = listi ) return i; return -1;void main ( ) int testsarrSize = 5658845, 4562555, 3852085, 4520125, 5552012; int result, x;请输入账号: result = searchList(tests, arrSize, x); if ( result = -1 ) cout x为非法账号。 endl; else为合法账号。4-5、采用二分查找实现上述程序。void selectionSort

11、(int a , int n) / 选择排序 int i, j, t, minIndex;n-1; minIndex=i; for(j=i+1; j j+) if(ajaminIndex) minIndex=j; if( minIndex != i ) t=aminIndex; aminIndex=ai; ai=t;/二分查找函数,在a数组中查找valueint binarySearch(int a , int numElems, int value) int low=0, mid, hight=numElems-1; while (low=hight) mid=(low+hight)/2;

12、if( value = amid ) / 查找成功 return mid; else if( value max) k=j; max=aij; /第i行第k列为第i行的最大元素 for(m=0, f=1; mp1&f; m+) if(amkmax) f=0; /第i行第k列不是鞍点 if(f) w=1; q1=i; q2=k; return w; int aMN=1, 2, 3, 4, 4, 5, 3, 6, 3, 5, 6, 7; /*2,4,10,6,3,4,5,8,9,1,2,3;*/ int w; w=andian(a,M,N); if(w) 该二维数组存在鞍点:aq1q2其行标为:q1t列标为:q2; else cout该二维数组没有鞍点。4-7、编写函数求一个44二维数组中周边元素的和。int arrSum(int arr4) int i,j,sum=0;4; sum+=arri0; sum+=arri3; for(j=0; sum+=arr0j; sum+=arr3j; sum

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1