请编写一个函数void fun(int a [],int n),其中a为数组,n为数组a的长度。函数fun()的功能是冒泡排序法将数组a元素按从小到大的顺序排列,实现数组a的升序排列。
注意:部分源程序已存在文件PROC12.cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun()的花括号中填写若干语句。
文件PROC12.cpp的内容如下:
//PROC12. cpp
include <iostream>
using namespace std;
define MAX 100
void fun(int a[],int n);
int main ()
{
int a[MAX],n,i;
cout<<"Please enter the array size n:\n";
do {
cin>>n;
if (n>100)
cout<<"array size flowover! ReEnter a number(0-100)\n";
}while (n>100);
cout<<"Enter the array data:\n";
for (i=0; i<n; i++)
cin>>a [ii;
fun(a[],n);
for (i=0; i<n; i++)
cout<<a [i] <<" ";
cout<<end1;
return 0;
}
void fun(int a[ ],int n)
{
// * * * * * * * *
}
第1题:
【其它】编写程序:设计一个一维数组的排序函数p_sort,并调用它对10个整数进行排序。p_sort函数原型如下: void p_sort(int *p,int n) 其中,p是指向int型一维数组的指针变量,n是数组长度。
第2题:
函数定义为Func(int *p),变量定义为n=100,则下面调用该函数正确的是?
A.Fun(20)
B.Fun(20+n)
C.Fun(n)
D.Fun(&n)
第3题:
请编写一个函数int fun(int *s,int t,int *k),用来求出数组的最大元素在数组中的下标并存放在k所指的存储单元中。
例如,输入如下整数:
876 675 896 101 301 401 980 431 451 777
则输出结果为6,980。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
int fun(int *s,int t,int *k)
{
}
main()
{
int a[10]={ 876,675,896,101,301,401,
980,431,451,777},k;
clrscr();
fun(a, 10, &k);
printf("%d, %d\n ", k, a[k]);
}
第4题:
请编写一个函数fun(),它的功能是:找出一维数组元素中最大的值和它所在的下标,最大值和它所在的下标通过形参传回。数组元素中的值已在主函数中赋予。
主函数中x是数组名,n是x中的数据个数,max存放最大值,index存放最大值所在元素的下标。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<stdlib.h>
include<stdio.h>
void fun(int a[],int n, int *max,int *d)
{
}
main()
{
int i, x[20], max, index, n=10;
randomize();
for(i=0; i<=n; i++)
{
x[i]=rand()%50;
printf("%4d",x[i]);
/*输出一个随机数组*/
}
printf("\n");
fun(x,n,&max,&index);
printf("Max=%5d,Index=%4d\n",max,index);
}
第5题:
若有函数
Void fun( double a[ ],int *n)
{ …… }
以下叙述中正确的是
A)调用fun函数时只有数组执行按值传送,其他实参和形参之间执行按地址传送
B)形参a和n都是指针变量
C)形参a是一个数组名,n是指针变量
D)调用fun函数时将把double型实参数组元素一一对应地传送给形参a数组
第6题:
若有函数 void fun(double a[]。int*n) {…} 以下叙述中正确的是( )。
A.调用fun函数时只有数组执行按值传送,其他实参和形参之间执行按地址传送
B.形参a和n都是指针变量
C.形参a是一个数组名,n是指针变量
D.调用fun函数时将把double型参数组元素一一对应地传送给形参a数组
第7题:
请编写一个函数int fun (int *s,int t,int *k),用来求出数组的最小元素在数组中的下标并存放在k所指的存储单元中。
例如,输入如下整数:
234 345 753 134 436 458 100 321 135 760
则输出结果为6,100。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio.h>
include<stdio.h>
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("%dr %d\n", k, a[k]);
}
第8题:
下列说法不正确的是
A.int *fun();----fun是一个返回int指针的函数
B.int (*fun)();---fun是一个返回int指针的函数
C.int (*array[5])();----array是一个有5个元素的数组,每一个元素都是一个函数指针,指向一个返回int的函数
D.int (*fun(int))(int);----fun是带有一个int参数的函数,返回值是一个函数指针,这个指针指向带有一个int参数并返回int的函数
第9题:
请编写函数fun(),该函数的功能是将M行N列的二维数组中的数据,按列的顺序依次放到一维数组中。
例如:二维数组中的数据为
33333333
44444444
55555555
则一维数组中的内容应是
334455334455334455334455。
注意:部分源程序以存在文件test_2.cpp中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
文件test39_2.cpp的内容如下:
include<stdio.h>
include<iostream.h>
void fun(int(*s) [10],int *b, int *n,int mm,int nn)
{
}
void main( )
{
int w[10][10]={{33,33,33,33},{44,44,44,44},{55,55,55,55}},i,j;
int a[100]={0}, n=0;
cout<<"The matrix:\n"
for(i=0; i<3; i++)
{
for(j=0; j<4; j++
cout<<w[i] [j];
cout<<endl;
}
fun(w, a, &n, 3, 4);
cout<<"The A array:\n";
for(i=0; i<n; i++)
cout<<a[i];
cout<<"\n\n";
}