题目详情
当前位置:首页 > 职业培训考试
题目详情:
发布时间:2024-05-27 19:21:55

[简答题]请编写一个函数sum(int array[],int len),该函数返回数组array的所有整数元素的和,其中len为数组array的长度。 注意:部分源程序已存在文件test34_2.cpp中。 请勿修改主函数main和其他函数中的任何内容,仅在函数sum的花括号中填写若干语句。 程序输出结果如下: sum of array 15 文件test34_2.cpp的内容如下: #include <iostream.h> int sum(int array[],int len) { } void main( ) { static int a[5]-{1,2,3,4,5}; int result=sum(a,5); cout<<"sum of array "<<result<<end1; }

更多"请编写一个函数sum(int array[],int len),该函数"的相关试题:

[简答题]请编写一个函数sum(int array[],int len),该函数返回数组array的所有整数元素的和,其中len为数组array的长度。
注意:部分源程序已存在文件test34_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数sum的花括号中填写若干语句。
程序输出结果如下:
sum of array 15
文件test34_2.cpp的内容如下:
#include <iostream.h>
int sum(int array[],int len)


void main( )

static int a[5]-1,2,3,4,5;
int result=sum(a,5);
cout<<"sum of array "<<result<<end1;

[简答题]简单应用题 请编写一个函数 int sum(int n),该函数完成1+2+3+…+n的运算,并返回运算结果,其中n>0。注意:请使用递归算法实现该函数。 注意:部分源程序已存在文件test11_2.cpp中。 请勿修改主函数main和其他函数中的任何内容,仅在函数sum的花括号中填写若干语句。 文件test11_2.cpp的内容如下: #include int sum(int n) { } void main( ) { int n; cout<<"输入n: "; cin>>n; int result=sum(n); cout<<"结果为:"<
[简答题]请编写一个函数int sum(int n),该函数完成1+2+3+…+n的运算,并返回运算结果,其中n>0。注意:请使用递归算法实现该函数。
注意:部分源程序已存在文件:test11.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数sum的花括号中填写若干语句。
文件test11_2.cpp的内容如下:
#include<iostream.h>
int sum(int n)


void main( )

int n;
cout<<"输入n:";
cin>>n;
int result;sum(n);
cout<<"结果为:"<<result<<endl;

[简答题]以下程序中函数int check (int *a,int *b,int len)的功能是:(1)将a指向的包含len个元素的整型数组中所有相邻元素值之差的绝对值依次存放在b指向的一维数组中;(2)检查b数组中所有元素的值是否组成一个公差大于0的等差数列,若是则函数返回1,否则函数返回0。例如:当a指向数组各元素的值是{-3,-2,1,6,13)时,b指向数组各元素的值{1,3,5,7}组成一个公差为2的等差数列,因此函数返回1。 #include #include #define M 5 #define N 10 /*tongj函数统计a指向二维数组每行中存放的连续非0整数个数并依次保存到n指向的数组中*/ void tongj(int a[][N],int n[]) { int i,j; for (i=0; i
[简答题]请编写一个函数inline long sum(int n),用递归函数完成运算:sum(n)=1*1+2*2+…n*n,递归表达式为 sum(n)=sum(n-1)+n2。
注意:部分源程序已存在文件test10_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数sum的花括号中填写若干语句。
文件test10_2.cpp的内容如下:
#include<iostream.h>
inline long sum(int n)


void main( )

int n;
cout<<"输入n:";
cin>>n;
cout<<"结果为:"<<sum(n)<<endl;

[简答题]请编写一个函数printdate(int year,int month,int day),该函数实现将输入的3个数字转换成英语数字纪年输出的功能,如输入March9,1978,则输出1978 3 9。注意:使用switch结构实现该函数的基本功能并应该能够判断错误的输入。部分源程序已存在文件test40_2.cpp中。请勿修改主函数main和其他函数中的任何内容,仅在函数printdate的花括号中填写若干语句。
源程序文件rest40_2.cpp清单如下:
#include<iostream.h>
void printdate(int year, int month, int day)


void main( )

printdate(1978,3,9);

[简答题]请编写一个函数comm(int n,int k),该函数将用递归算法计算从n个人中选择k个人组成一个委员会的不同组合数,由n个人里选k个人的组合数=由(n-1)个人里选k个人的组合数+由(n-1)个人里选(k-1)个人的组合数。 注意:部分源程序已存在文件test41_2.cpp中。 请勿修改主函数main和其他函数中的任何内容,仅在函数comm的花括号中填写若干语句。 源程序文件test41-2.cpp清单如下: #include<iostream.h> int comm(int n, int k) { } void main ( ) { int n=7, k=3; cout<<"n=7,k=3"<<endl; cout<<comm(n,k)<<endl; }
[简答题]请编写一个函数fun(int score [][3],int num),该函数返回有一门成绩以上课程成绩在85分以上,其余课程成绩不低于70分的人数。数组score按行存放num名考生各自的三门期末考试成绩。 注意:部分源程序已存在文件test31_2.cpp中。 请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。 程序输出结果如下: 3 文件test31_2.cpp清单如下: #include <iostream.h> int fun(int score[] [3],int num) { } void main ( ) { int score[4] [3]={{70,89,92},{70,76,93},(80,86,98},{65,73,45}); cout<<fun(score,4)<<end1; }
[简答题]请编写一个函数maxofarray(atype*p,int count),该函数从一个数组中找出其中的最大元素,并且数组中可以存放多种数据类型的元素。
注意:部分源程序己存在文件test42_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数maxofarray的花括号中填写若干语句。
文件test42_2.cpp清单如下:
#include<iostream.h>
#include<string.h>
#include<conio.h>
template<class atype>
void maxofarray(atype* p,int count)


void main ( )

int len=5;
char *p1;
cout<<"the char type array and it’s length is 5:/n";
cout<<"the array element is a b c d e/n";
p1=new char[len];
for (int i=0;i<len;i++)
p1[i]=’a’+i;
maxofarray(p1,len);

[简答题]请编写两个函数int sum_of_powers(int k,int n),powers(int m,int n),求1~6的k次方的和,sum_of_powers中参数k和n分别表示k次方和所求数列中最大的一个自然数,最后返回所求值,powers中参数m和n分别表示m为底数n为指数,最后返回所求值。要求使用for循环和函数嵌套(int sum_of_powers中调用powers)实现算法。输出结果如下:
sum of 4 powers of intergers from 1 to 6=2275
注意:部分源程序已存在文件test25_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数sum_of_powers和powers的花括号中填写若干语句。
文件test25_2.cpp的内容如下:
#include<iostream.h>
const int k(4);
const int n(6);
int sum_of_powers(int k,int n),powers(int m,int n);
void main( )

cout<<"sum of "<<k<<" powers Of intergers from 1 to "<<n<<"=";
cout<<sum_of_powers(k,n)<<endl;

int sum_of_powers(int k,int n)


int powers(int m, int n)


[填空题]求1到n的自然数之和的函数。
#include"stdio.h"
int sum(int n)
int k,s=0;
for(k=1;k<10;k++)
s=s+k:
return s;

错误:______
改正:______
[简答题]请编写一个函数fun(int x,int n),该函数返回x的n次幂的值,其中x和n都是非负整数。x的n次幂的计算方法是1与x相乘n次,如x的20次幂的计算为1与x相乘20次,
注意:部分源程序已存在文件test30_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。
如输入3和4,输出结果如下:
3 4
81
文件test30_2.cpp清单如下:
#include<iostream.h>
double fun(int x, int n)


void main ( )

int x,n;
cin>>x>>n;
cout<<fun(x,n)<<end1;

我来回答:

购买搜题卡查看答案
[会员特权] 开通VIP, 查看 全部题目答案
[会员特权] 享免全部广告特权
推荐91天
¥36.8
¥80元
31天
¥20.8
¥40元
365天
¥88.8
¥188元
请选择支付方式
  • 微信支付
  • 支付宝支付
点击支付即表示同意并接受了《购买须知》
立即支付 系统将自动为您注册账号
请使用微信扫码支付

订单号:

请不要关闭本页面,支付完成后请点击【支付完成】按钮
恭喜您,购买搜题卡成功
重要提示:请拍照或截图保存账号密码!
我要搜题网官网:https://www.woyaosouti.com
我已记住账号密码