题目详情
当前位置:首页 > 计算机考试 > 初级程序员
题目详情:
发布时间:2023-11-11 23:00:45

[简答题]【说明】
请编写一个函数int SeqSearch(int list[],int start,int n,int key),该函数从start开始,在大小为n的数组list中查找key值,返回最先找到的key值的位置,如果没有找到则返回-1。请修改程序中画线部分的错误并将不同情况下的输出结果补充完整。
【程序】
文件search.cpp的内容如下:
#include <iostream. h >
int SeqSearch( int list[ ] ,int start,int n,int key)

for(int i=start;i<=n;i++) //(1)

if( list[i] = key)//(2)

return i;


return -1;

void main( )

int A[10]
int key,count=0,pos;
cout <<" Enter a list of 10 integers:";
for(pos=0;pos<10;pos++)

cin >>A; //(3)

cout <<" Enter a key; ";
cin >> key;
pos=0;
while(( pos = SeqSearch ( A, pos, 10, key)) !=-1 )

count ++;
pos ++;

cout<<key<<"occurs" <<count<< (count!=1" times":" time") <<" in the list,"
<< endl;

第一种情况:输入2 3 12 6 8 45 8 33 7输入key:8
输出: (4)
第二种情况:输入2 3 126

更多"【说明】 请编写一个函数int SeqSearch(int list"的相关试题:

[简答题]请编写一个函数int SeqSearch(int list[],int start,int n,int key),该函数从start开始,在大小为n的数细list中查找key值,返回最先找到的key值的位置,如果没有找到则返回-1。请使用for循环实现。
注意:部分源程序已存在文件test19_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数SeqSearch的花括号中填写若干语句。
文件test19_2.cpp的内容如下:
#include <iostream.h>
int SeqSearch(int list[], int start, int n, int key)


void main( )

int A[10];
int key, count=0, pos;
cout<<"Enter a list of 10 integers: ";
for(pos=0;pos<10;pos++)

cin>>A[pos];

cout<<"Enter a key: ";
cin>>key;
pos=0;
while( (pos=SeqSearch(A, pos,10,key))!=-1)

count++;
pos++;

cout<<key<<" occurs "<<count<<(count!=1" times":" time")<<" in the list."<<end1;

[简答题]请编写一个函数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); }
[简答题]请编写一个函数int fun (int nFirst, int nSecond),求两个数的最小公倍数并返回这个值。
注意:部分源程序已存在文件test13_2.cpp中。如输入7和8时,结果是56。
请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。
文件test13_2的内容如下;
#include<iostream.h>
int fun(int nFirst,int nSecond);
void main( )

int nFirst,nSecond;
cout<<"Please input the first one";
cin>>nFirst;
cout<<" Please input the second one";
cin>>nSecond;
cout<<"最小公倍数:"<<fun(nFirst,nSecond)<<endl;

int fun(int nFirst,int nSecond)


[多项选择]简单应用题 请编写一个函数int fun(int nFirst,int nSecond),求两个数的最小公倍数并返回这个值。 注意:部分源程序已存在文件test13_2.cpp中。如输入7和8时,结果是56。 请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。 文件test13_2的内容如下: #include int fun(int nFirst,int nSecond); void main( ) { int nFirst, nSecond; cout<<"Please input the first one/n"; cin>>nFirst; cout<<"Please input the second one/n"; cin>>nSecond; cout<<"最小公倍数:"<
[多项选择]编程题 请编写一个函数void fun(int m, int k, int xx[]),该函数的功能是:将大于整数m且紧靠m的k个非素数存入所指的数组中。 例如,若输入15,5,则应输出16,18,20,21,22。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include #include void fun(int m, int k, int xx[]) { } main( ) { int m,n,zz[1000]; clrscr( ); printf("/nPlease enter two integers: "); scanf("%d%d",&m,&n); fun(m, n, zz); for(m=0;m
[简答题]请编写一个函数void fun(int m, int k, int xx[]),该函数的功能是将大于整数m且紧靠m的k个非素数存入所指的数组中。
例如,若输入15,5,则应输出16,18,20,21,22。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <conio.h>
#include <stdio.h>
void fun(int m,int k,int xx[])

main( )

int m,n,zz[1000];
clrscr( );
printf("/nPlease enter two integers:");
scanf("%d%d",&m,&n);
fun(m,n,zz);
for(m=0;m<n;m++)
printf("%d",zz[m]);
printf("/n");

[多项选择]请编写一个函数jS Value(int m, int k, int xx[]),该函数的功能是:将小于整数m且紧靠m的k个素数存入数组xx并传回。调用函数writeDat( )读取10组数据,分别得出结果且把结果输出到文件out.dat中。
注意:部分源程序给出如下。
例如:若输入“17,5”,则应输出“13,11,7,5,3”。
请勿改动主函数main( )和输出数据函数readwriteDat( )的内容。
[试题源程序]
#include<conio.h>
#include<stdio.h>
void readwriteDat( );
void num(int m, int k, int xx[])


main( )

int m, n, xx[1000];
System("cls");
printf("/nPlease enter two integers:");
Scanf("%d%d", &m, &n);
num(m,n,xx);
for(m=0;m<n;m++)
printf("%d",xx[m]);
printf("/n");
readwriteDat( );

void readwriteDat( )

int m,n,xx[1000],i;
FILE *rf,*wf;
rf=fopen("in.dat","r");
wf=fopen("out.dat","w");
for(i=0;i<10;i++)

Scanf(rf,"%d%d",&m,&n);
num(m,n,xx);
for(m=0;m<n;m++) fprintf(wf,"%d",xx[m]);
fprintf(wf,"/n");

fclose(rf);
fclose(wf);

[多项选择]编程题 请编写一个函数int fun(int *s,int t,int *k),用来求出数组的最小元素在数组中的下标并存放在k所指的存储单元中。 例如,输入如下整数: 234 345 753 134 436 458 100 321 135 760 则输出结果为6,100。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include #include int fun(int *s,int t,int *k) { } main( ) { int a[10]={234,345,753,134,436,458,100,321,135,760},k; clrscr( ); fun(a, 10, &k); printf("%d, %d/n ", k, a[k]); }
[简答题]请编写一个函数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; }
[简答题]请编写一个函数void fun(int m, int k, int xx[]),该函数的功能是:将大于整数m且紧靠m的k个素数存入所指的数组中。 例如,若输入17,5,则应输出19,23,29,3l,37。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include <conio.h> #include <stdio.h> void fun(int m, int k, int xx[]) { } main( ) { int m,n, zz[1000]; clrscr( ); printf("/nPlease enter two integers: "); scanf("%d%d",&m,&n); fun(m,n,zz); for(m=O;m<n;m++) printf("%d ",zz[m]); printf("/n "); }
[简答题]请编写一个函数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; }
[简答题]请编写一个函数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;

我来回答:

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

订单号:

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