中南大学c++题库编程答案.pdf

上传人:奔*** 文档编号:89651028 上传时间:2023-05-08 格式:PDF 页数:172 大小:7.57MB
返回 下载 相关 举报
中南大学c++题库编程答案.pdf_第1页
第1页 / 共172页
中南大学c++题库编程答案.pdf_第2页
第2页 / 共172页
点击查看更多>>
资源描述

《中南大学c++题库编程答案.pdf》由会员分享,可在线阅读,更多相关《中南大学c++题库编程答案.pdf(172页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、1.计算分段函数:(O S 17 +Y 1=0使用库函数sqrt来计算平方根。f ti n cl u de f ti n cl u de tti n cl u de u si n g n am e space std;i n t m ai n()(do u bl e x,y;co u t”请输入一个 数x:ci n x;i f(x!=0)y=si n (x)+(sqrt(x*x+l);e l sey=co s(x)-x*x+3*x;co u t 函数值:se tpre ci si o n(6)ye n dl;re tu rn 0;)2.编写程序,输入某大写字母的ASCII码值,输出该字母的对应

2、小写字母。f ti n cl u de u si n g n am e space std;i n t m ai n()(i n t a=,a,-,A,;i n t x;w h i l e(ci n x)i f (x=A&x=,Z )co u t,/,z(ch ar)(x+a)e n dl;e l seco u t “输入的不是大写字母的AS CI I码“e n dl;)re tu rn 0;)3.用牛顿迭代法求方程:3x 3-4x 2-5 x+13=0在x=l附近的根,要求精度为10-6 o#i n cl u de#i n cl u de u si n g n am e space std;

3、i n t m ai n()(f l o at xn,xn l,f,f l;co u t 请输入x的初值:;ci n xn l;doxn=xnl;f=(3*(xn-4/3)*xn-5)*xn+15;fl=(9*xn-8)*xn-5;xnl=xn-f7fl;while(fabs(xn 1 -xn)=1 e-6);cout方程的 个根:xn lendl;return 0;)4.编写函数fun(),它的功能是利用以下所示的简单迭代方法求方程cos(x)-x=0 的一个实根。x n+1=cos(x n)#include#include float value()(float xO,x1;xO=0;x1

4、=cos(xO);while(abs(xO-x1)=0.000001)(xO=x1;x1=cos(xO);)return x1;)void main()(printf(迭代方法求方程:cos(x)-x=0的解为%fn,value();)5.编写函数i n t f (i n t x,i n t n),求出20个数中的最大数,并在以下m ai n 函数中进行测试。#i n cl u de vo i d ma in()(i n ta =1,4,6,7,3,9,10,30,5 9,32,48,7 2,8 7,13,27,45,6 4,8,2,6);co u tXa 中最大值为:Xf (a,20)e n

5、 dl;f ti n cl u de stdaf x.h f ti n cl u de u si n g n am e space std;i n t f (i n t x,i n t n);i n t m ai n(i n t arg c,ch ar*arg v)(i n t a 2 0 =1,8,10,3,7,15,28,2,4,22,0,17,25,9,19,6,14,26,20,11;pri n tf (,zm ax i s%dn”,f (a,20);re tu rn 0;)i n t f (i n t x,i n t n)(i n t i;i n t m a x;m ax=x 0;f

6、 o r(i=l;i n;i+)i f (m axx i)m ax=x i ;)re tu rn m a x;re tu rn 0;)6.将给定的十进制数转换为十六进制数。f ti n cl u de u si n g n am e space std;i n t m a i n 0(i n t x;w h i l e(ci n x)pri n tf (%X H n,/,x);)re tu rn 0;7.编写一个自定义函数:i n t f(i n t M,i n t N),f()的功能是:对给定的正整数M和 N,找出满足方程“5 x+6 y=M 的正整数解中x 和y 都是偶数的解。要求:若 M

7、和 N不都是正整数,则结束函数并返回一1;只有M和 N都是正整数时,才继续求解操作,并用二重循环进行求解:(1)在函数中输出满足条件的正整数解x 和 y,(2)使函数值返回满足条件的正整数解的组数。f ti n cl u de u si n g n am e space std;i n t f (i n t M,i n t N);vo i d m ai n()co u t f (5 00,6 5 0)e n dl;f ti n cl u de u si n g n am e space std;i n t f (i n t M,i n t N);vo i d m ai n()co u tf (

8、5 00,6 5 0)e n dl;i n t f (i n t M,i n t N )(i n t x,y,co u n t=0;i f(M 1|N 1)re tu rn -1;f o r(x=2;x=N/5 ;x+=2)(f o r(y=2;y=M/6 ;y+=2)(i f(5*x+6*y=M )co u n t+;co u t “x=,x,/y=,y e n d l;re tu rn (co u n t?co u n t:-1);)8.编写一个解“一百元买鸡”问题的自定义函数:i n t f(i n t M,i n t N),其中M代表公鸡的单价(元/只),N代表母鸡的单价(元/只),价

9、格由主调函数给定;购鸡方案中要求总花费刚好为100元,且不允许全部购买公鸡或全部购买母鸡(即公鸡、母鸡只数 都不能为0);求解所有购鸡方案。若M和N只要有一个以上参数无意义,则函数结束执行并返回一1值;若M和N都有意义,则函数输出所有可能的购鸡方案,并返回方案的组数。要求用二重循环实现。#i n cl u de u si n g n am e space std;int f(int M,int N);void main()coutf(15,28)endl;ftinclude using namespace std;int f(int M,int N);void main()coutf(30,2

10、0)endl;int f(int M,int N )(int x,y,count=0;if(M 1|N 1)return-1;for(x=1;x=100/M;x+)f o r(y=1 ;y=100/N&(M*x+N*y=100);y+)i f (M*x+N*y=100)co u n t+;co u tX公 鸡=母 鸡=,ye n dl;re tu rn (co u n t?co u n t:-1);9.编写一个自定义函数:i n t f(l o n g a,i n t n,l o n g x),f()的功能是:对给定的含有n 个元素的一维数组a 及某个指定数x,查找数组a中是否存在元素值等于x

11、的元素,若存在,则函数值返回找到的下标最大的那个元素的下标;若不存在,则函数值返回-lo#i n cl u de u si n g n am e space std;i n t f (l o n g a口,i n t n,l o n g x);vo i d m ai n()l o n g x=7;l o n g a5 =3,5,2,7,9);co u tf (a,5,x)e n dl;f ti n cl u de u si n g n am e space std;i n t f (l o n g a,i n t n,l o n g x);vo i d m ai n()long x=7;lon

12、g a5=3,5,2,7,9);coutf(a,5,x)endl;)int f(long a,int n,long x)(int count=0,pos=-1;for(int i=0;i n;i+)(if(ai=x )(pos=i;count+;i f (co u n t=0)re tu rn -1;re tu rn p o s;)10.编写一个自定义函数:i n t f(l o n g a,i n t n,l o n g x),f()的功能是:对给定的一维数组a及某个指定数x,找出数组a中元素值等于x的元素个数,以及最后一个值为x的元素所在位置下标。在函数中输出这两个结果,并将找到的元素个数

13、作为函数值返回。#i n cl u de u si n g n am e space std;i n t f (l o n g a,i n t n,l o n g x);vo i d m ai n()l o n g x=7;l o n g a5 =3,7,2,7,9 :coutf(a,5,x)endl;ttinclude using namespace std;int f(long a,int n,long x);void main()long x=7;long a5=3,5,2,7,9;coutf(a,5,x)en d l;)int f(long a,int n,long x)(int co

14、unt=0,pos=-1;fo r(int i=0;i n;i+)i f (ai=x)po s=i;co u n t+;)co u t co u n t,z ,zi e n dl;re tu rn co u n t;)11.编写一个自定义函数:i n t f(l o n g a口,i n t n,l o n g x),f()的功能是:对给定的含有n个元素的一维数组a及某个指定数x,查找数组a中是否存在元素值等于x的元素,若存在,则函数值返回I找到的下标最小的那个元素的下标;若不存在,则函数值返回-1。tti n cl u de u si n g n am e space std;i n t f

15、 (l o n g a口,i n t n,l o n g x);vo i d m ai n()l o n g x=8;l o n g a5 =3,7,2,7,9);co u tf (a,5,x)e n dl;tti n cl u de u si n g n am e space std;i n t f (l o n g a,i n t n,l o n g x);vo i d m ai n()l o n g x=7;l o n g a5 =3,5,2,7,9 ;co u t=0;i一)i f (ai=x)po s=i;co u n t+;)i f (co u n t=0)re tu rn -1;

16、re tu rn po s;12.编写一个自定义函数:i n t f(i n t N),f()的功能是:对给定的正整数N,找出满足下列方程“3x+4y=N”的正整数解。若N不是正整数,则结束函数并返回一1;若N是正整数,则函数中输出找到的所有正整数解,并且使函数值返回解的组数。用二重循环实现。#i n cl u de u si n g n am e space std;i n t f (i n t N);vo i d m ai n()co u tf (16 0)e n dl;f ti n cl u de u si n g n am e space std;i n t f (i n t N);v

17、o i d m ai n()co u t f (16 0)e n dl;syste m (pau se);i n t f(i n t N )(i n t x,y,co u n t=0;f o r(x=1 ;x=N/3;x+)f o r(y=1;y=N/4;y+)(i f (3*x+4*y=N )(co u n t+;co u tXx=y=,y e n d l;re tu rn (co u n t?co u n t:-l);)13.编写一个解“鸡兔共笼”问题的自定义函数:i n t f(i n t N),其中N代表动物的脚总数;且笼中每种动物都至少有1只以上。若N不符合实际,则结束函数并返叵1

18、1;若N符合实际要求,则函数输出所有可能的鸡、兔数,并返回符合条件解的组数。用二重 循环实现。f ti n cl u de u si n g n am e space std;i n t f (i n t N);vo i d m ai n()co u tf (16 0)e n dl;tti n cl u de u si n g n am e space std;i n t f (i n t N);vo i d m ai n()co u tf(16 0)e n dl;i n t f(i n t N )(i n t x,y,co u n t=0;f o r(x=1;x=N/2;x+)(f o r(

19、y=1;y=N/4;y+)(i f(2*x+4*y=N )(co u n t+;co u t鸡=兔=,y e n d l;re tu rn (co u n t?co u n t:-l);14.编写-个自定义函数:i n t f(i n t M),f()的功能是:对给定的正整数M,找出满足方程“5 x+6 y=M且x不超过100的正整数解。若M不是正整数,则结束函数并返回一1;若M是正整数时,则函数中输出所有的正整数解,并且使函数值返回正整数解的组数,要求使用一重循环。f ti n cl u de u si n g n am e space std;i n t f(i n t M);void m

20、ain()coutf(500)endl;ttinclude using namespace std;int f(int M);void main()coutf(500)endl;int f(int M )(int x,y,count=0;int t;if(M =0)return-1;for(x=1;x=M/5&x=100;x+)t=(100-5*x)/6;i f (5*x+6*t=M )(co u n t+;co u t,x=,x/,y=,te n dl;)re tu rn (co u n t?co u n t:-1);)15编写一个自定义函数:i n t f(i n t M,i n t N)

21、,f ()的功能是:对给定的正整数M和N,找出满足方程“7 x+4y=M 的正整数解中x是偶数且y是奇数的解。要求:若M和N不都是正整数,则结束函数并返回一1;只有M和N都是正整数时,才继续求解操作,用二重循环进行求解:(1)在函数中输出满足条件的正整数解x和y,(2)并且使函数值返回满足条件的正整数解的组数。ttinclude using namespace std;int f(int M,int N);void main()coutf(500,650)endl;ttinclude using namespace std;int f(int M,int N);void main()coutf

22、(500,650)en d l;int f(int M,int N )(int x,y,count=0;if(M 1|N 1)return T;f o r(x=2;x=N/7 ;x+=2)f o r(y=1;y=M/4;y+=2)i f(7*x+4*y=M )co u n t+;co u t,x=,x/,y=/,y e n d l;)re tu rn (co u n t?co u n t:-l);16.编写一个自定义函数:i n t f(ch ar x,i n t N),f()的功能是:对给定的字符c和整数N,用c代表的符号打印一个N行的图案,每行开头没有任何空格。比如,当c为*且N为5时 一

23、,打印的图案如本题图所示。且函数值返回1。#inclu de u s ing na me s p a ce s t d;int f(ch a r x,int N);vo id ma in()ft inclu de u s ing na me s p a ce s t d;int f(ch a r x,int N);vo id ma in()ch a r x;int n,i,m;co u t xn;fo r (i=l;i=n;i+)(fo r(m=l;m=i;m+)co u t x;co u t e ndl;)17.编写一个自定义函数:int f(ch a r x,int N),f()的功能是:

24、对给定的字符c和整数N,用c代表的符号打印一个N行的图案,每行开头没有任何空格。比如,当c为丁且N为5时 一,打印的图案如本题图所示。且函数值返回1。TTTr i n rT i n i r iTTTTTTTTTt t inclu de u s ing na me s p a ce s t d;int f(ch a r x,int N);vo id ma in()f c r,5);)t t inclu de u s ing na me s p a ce s t d;int f(ch a r x,int N);vo id ma in()ch a r x;int n,i,m;co u t xn;fo

25、 r (i=l;i=2*n;i=i+2)(fo r(m=l;m=i;m+)co u t x;co u t e ndl;)18.编写一个自定义函数:int f(int N),f()的功能是:对给定的正整数N,打印一-个N行N列的由 A、B、C以及空格 符号组成的方阵图案。比如,当N为5时,打印的图案如本题图所示。且函数值返回loft inclu de u s ing na me s p a ce s t d;int f(int N);vo id ma in()f;ft inclu de u s ing na me s p a ce s t d;int f(int N);vo id ma in()

26、(int n;co u t ,请输入一 数:n;f(n);)int f(int N)(int i,m;fo r(i=l;i=N;i+)(for(m=l;m=N;m+)(i f(m=l|m=i)couti)cout,B;e ls eco u t C ;co u t e ndl;)r e t u r n 1;)19.编写一个自定义函数:int f(int N),f()的功能是:对给定的正整数N 1 0,打印一个N行N列的由数字、字符 P、K、空格 组成的方阵图案。比如,当N为5时,打印的图案如本题图所示。且函数值返叵11。ft inclu de u s ing na me s p a ce s t

27、 d;int f(int N);vo id ma in()f(5);t t inclu de u s ing na me s p a ce s t d;int f(int N);vo id ma in()(int n;co u t ”请输入一个数:n;f(n);int f(int N)int i,m;fo r(i=l;i=N;i+)(for(m=l;m=N;m+)(if(i=l)couti)cout,/K else if(mi)cout,P elsecoutmz/co u t en dl;r e t u r n 1;)20.本题在主函数中给定个数N,通过调用自定义函数f得 到:TN区间中不能被

28、3整除的数之和。请根据函数f的声明语句及其功能完成函数代码设计。ft inclu de u s ing na me s p a ce s t d;int f(int m);ma in()int n;co u t n;co u t f(n);ft inclu de u s ing na me s p a ce s t d;int f(int m)int s u m=O;fo r(int i=l;i=m;i+)if(i%3!=0)s u m+=i;)r e t u r n s u m;vo id ma in()int n;co u t,p le a s e e nt e r n:;cin n;co

29、 u t f(n);)21.本题在主函数中给定数组a及其元素个数n,通过调用自定义函数f,使数组a的元素反序存放:即第1个位置的元素与倒数第1个 位置的元素交换,第2个位置的元素与倒数第2个位置的元素交换,如此类推。交换的元素组数与元素总数n有关。要求n在主函数中给定。根据主函数代码和函数f的声明,完成自定义函数设计。ft inclu de u s ing na me s p a ce s t d;vo id f(int x ,int n);void main()int i,a10;for(i=0;i=10-l;i+)cinai;f(a,10);for(i=0;i=10-l;i+)coutai

30、,);)ftinclude using namespace std;void f(int x,int n)int tmp;for(int i=0;in/2;i+)tmp=x i;xi=x n-i-l;xn-i-l=tmp;void main()int i,a10;for(i=0;i=10-l;i+)c in a i;f(a,10);for(i=0;i=10T;i+)c o u t a i ,)22,本题在主函数中给定个数N,通过调用自定义函数f得 至MlN区间的偶数和。请根据函数f的声明语句及其功能完成函数代码设计。ft inclu de u s ing na me s p a ce s t

31、d;int f(int m);ma in()int n;co u t,p le a s e e nt e r n”;cin n;co u t f(n);ftinclude using namespace std;int f(int m)int sum=O;for(int i=0;i=m;i+)if(i%2=0)sum+=i;)return sum;int main0 int n;co u t,p le a s e e nt e r n”;cin n;co u t f(n);)23.本题在主函数中给定个数N,通过调用自定义函数f 得到1N区间的奇数和。请根据函数f 的声明语句及其功能完成f 函数

32、代码设 计。t t inclu de u s ing na me s p a ce s t d;int f(int m);ma in()int n;co u t n;coutf(n);ttinclude using namespace std;int f(int m)int sum=O;for(int i=0;i=m;i+)if(i%2!=0)sum+=i;return sum;int ma in0 int n;co u t,/p le a s e e nt e r n”;cin n;co u t f(n);)24.本题在主函数中给定数组a及其元素个数n,通过调用自定义函数f得到给定数组中的所

33、有元素之和。请根据函数f的声明语句及其功能完成f函数代码设计。ft inclu de u s ing na me s p a ce s t d;ft de fine N 10int f(int x ,int n);void main()int i,aN;for(i=0;i=N-l;i+)c in a i;coutf(a,N);ttinclude using namespace std;ftdefine N 10int f(int x,int n)(int sum=0;for(int i=0;in;i+)sum+=x i;r e t u r n s u m;)vo id ma in()int i

34、,a N;fo r (i=0;ia i;co u t f(a,N);)25.本题在主函数中给定数组a及其元素个数n,通过调用自定义函数f求给定一维数组中所有下标为偶数的元素之和。请根据函数f的声明语句及其功能完成函数代码设计。ft inclu de u s ing na me s p a ce s t dftdefine N 10int f(int x,int n);void main()int i,aN;for(i=0;iai;coutf(a,N);)ftinclude using namespace std;ttdefine N 10int f(int x,int n)int i,s u

35、m=O;fo r(i=0;in;i+=2)s u m+=x i;r e t u r n s u m;)vo id ma in()int i,a N;fo r (i=0;i=N-l;i+)cin a i;co u t f(a,N);)26.本题在主函数中给定数组a及其元素个数n,通过调用自定义函数 f 求给定一维数组中所有下标为奇数的元素之和。请根据函数f的声明语句及其功能完成函数代码设计。ttinclude using namespace std;#define N 10int f(int x,int n);void main()int i,aN;for(i=0;i=N-l;i+)cinai;

36、coutf(a,N);)ttinclude using namespace std;ftdefine N 10int f(int x,int n);void main()int i,aN;for(i=0;i=N-l;i+)c in a i;coutf(a,N);)int f(int array,int n)(int sum=0;for(int i=l;in;i+=2)(sum+=arrayi;return sum;)27.本题在主函数中给定方阵数组a及其行数(列数)M,通过调用自定义函数f求给定二维数组中所有上三角元素(不含主对角线)之和。请根据函数f的声明语句及其功能完成f函数代码设计。t

37、t inclu de u s ing na me s p a ce s t d;ft de fine M 3int f(int x M );vo id ma in()int i,j,a M M ;fo r (i=0;i=M-l;i+)fo r (j=0;j=M-l;j+)cin a i j;co u t f(a);)ttinclude using namespace std;#define M 3int f(int x M);void main()int i,j,aM M;for(i=0;i=M-l;i+)for(j=0;j+)cinai j;coutf(a)endl;int f(int x

38、M)int s u m=O;int i,j;fo r (i=0;iM;i+)(fo r(j=i+l;jM;j+)(s u m+=x i j;)r e t u r n s u m;)28.本题在主函数中给定方阵数组a及其行数(列数)M,通过调用自定义函数f求给定二维数组中所有下三角元素(不含主对角线)之和。请根据函数f的声明语句及其功能完成f函数代码设计。ttinclude using namespace std;#define M 3int f(int x M);void main()int i,j,aM M;for(i=0;i=M-l;i+)for(j=0;j+)cinai j;coutf(

39、a);ttinclude using namespace std;ttdefine M 3int f(int x M);void main()int i,j,aM M;for(i=0;i=M-l;i+)for(j=0;j=M-l;j+)c in a i j ;coutf(a)endl;)int f(int x M)int sum=0,i,j;for(i=0;iM;i+)for(j=0;j i;j+)s u m+=x i j;r e t u r n s u m;)29.本题在主函数中给定方阵数组a及其行数(列数)M,通过调用自定义函数f求给定二维数组中所有主对角线上元素之和。请根据函数f的声明语

40、句及其功能完成f函数代码设计。#inclu de u s ing na me s p a ce s t d;ft de fine M 3int f(int x M );vo id ma in()int i,j,aM M;for(i=0;i=M-l;i+)for(j=0;j=M-l;j+)c in a i j ;coutf(a);)ttinclude using namespace std;#define M 3int f(int x M);void main()int i,j,aM M;for(i=0;i=M-l;i+)for(j=0;j=M-l;j+)cinai j;coutf(a)endl

41、;)int f(int x M)(int sum=O;for(int i=0;iM;i+)(sum+=xii;)return sum;30.通过调用自定义函数f求有规律的数列 1,2,4,8,16,中前n项之和,其中n在主函数中给定。请根据函数f的声明语句及其功能 完 成f函数代码设计。#inclu de u s ing na me s p a ce s t d;int f(int m);ma in()int n;co u t n;co u t f(n);)t t inclu de u s ing na me s p a ce s t d;int f(int m);main()int n;co

42、utn;coutf(n);)int f(int n)(int sum=0;for(int i=0;in;i+)(int value_=l;for(int j=0;j i;j+)va lu e _ *=2;s u m+=va lu e _;)r e t u r n s u m;)31.通过调用自定义函数f求有规律的数列1,4,9,16,25,中前n项之和,其中n在主函数中给定。请根据函数f的声明语句及其功能完成f函数代码设计。t t inclu de u s ing na me s p a ce s t d;int f(int m);ma in()int n;co u t n;coutf(n);

43、ttinclude using namespace std;int f(int m);main()int n;coutn;coutf(n);)int f(int n)int sum=0;fo r (int i=l;i=n;i+)s u m+=i*i;)r e t u r n s u m;)32.本题在主函数中给定个数N,通过调用自定义函数f得 到 :TN区间中能被3整除的数之和。请根据函数f的声明语句及其功能完成f函数代码设计。ft inclu de u s ing na me s p a ce s t d;int f(int m);ma in()int n;coutn;coutf(n);ft

44、include using namespace std;int f(int m);main()int n;cout,please enter n”;cinn;coutf(n);)int f(int m)int i=l,s u m=O;wh ile (i=m)(if(i%3=0)s u m+=i;i+;)r e t u r n s u m;)33.编写自定义函数f()的功能是找出一个数组a中第3大的元素,将该元素的值作为函数值返回,数组a及其元素个数m山主函数给定。根据自定义函数f的声明语句和功能编写f函数的代码。ft inclu de u s ing na me s p a ce s t d;

45、int f(int a,int m);main()(int a10=21,33,22,23,45,46,32,21,3,4;cout,The result is,/f(a,10)en d l;ttinclude using namespace std;int f(int a,int n);main()(int a10=21,33,22,23,45,46,32,21,3,4;cout,The result is,zf(a,10)endl;int f(int a,int m)int i=0,j=l,temp;while(im)(j=i+l;while(jm)(if(ai=aj)(temp=ai;a

46、i=aj;aj=temp;)j+;i+;)r e t u r n a 2;)34.编写函数f(),求具有n个元素的一维数组a中最大元素的下标(如果有多个并列最大的元素,则以最后一个为准)。其中,数组a及其元素个数n由主函数给定。ft inclu de u s ing na me s p a ce s t d;int f(int a ,int n);ma in()int a10=21,33,22,23,45,46,32,21,3,4;cout,The result is/f(a,10)endl;)ftinclude using namespace std;int f(int a,int n);m

47、ain()(int a10=21,33,22,23,45,46,32,21,3,4;cout,zThe result is,?f(a,10)endl;)int f(int a,int m)int i=0,n,temp;t e mp=a O ;wh ile(i=t e mp)t e mp=a i;n=i;i+;)r e t u r n n;35.编写函数f O,求具有n个元素的一维数组a中最大偶数元素的下标,函数值返回该元素下标;若无偶元素,函数值返回T。如果有多个并列最大的偶数元素,则以最后一个为准。其中,数组a及其元素个数n由主函数给定。ft inclu de u s ing na me s

48、 p a ce s t d;int f(int a ,int n);ma in()(int a 10 =21,33,22,23,45,46,32,21,3,4;co u t,T h e r e s u lt is z/f(a,10)e n d l;)t t inclu de u s ing na me s p a ce s t d;int f(int a ,int n);ma in()int a10=21,33,22,23,45,46,32,21,3,4;cout,The result is 10)endl;)int f(int a,int m)(int i=0,temp,n,flag=O;w

49、hile(i10)(if(ai%2=0)(temp=ai;flag=l;break;i+;while(i=temp&ai%2=0)temp=ai;n=i;i+;if(flag=O)r e t u r n-1;r e t u r n n;36.编写函数f(),求具有n个元素的一维数组a中最大奇数元素的下标,函数值返回该元素下标;若无奇元素,函数值返回T。如果有多个并列最大的奇数元素,则以最后一个为准。其中,数组a及其元素个数n山主函数给定。ft inclu de u s ing na me s p a ce s t dint f(int a口,int n);ma in()int a 10 =21

50、,33,22,23,45,46,32,21,3,4;co u t,T h e r e s u lt is z,f (a,10)e n d l;)ftinclude using namespace std;int f(int a,int n);main()(int a10=21,33,22,23,45,46,32,21,3,4;cout,The result is z,f (a,10)endl;)int f(int a,int m)(int i=0,temp,n,flag=0;while(i10)if(ai%2=l)tem p=ai;flag=l;break;)i+;)while(i=temp&

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com