更多"给定一个函数,其函数功能为:使10个整数按由小到大的顺序排列。在主函数"的相关试题:
[简答题]给定一个函数,其函数功能为:使10个整数按由小到大的顺序排列。在主函数中输入10个数,并输出结果。使用VC6打开考生文件夹下的工程RevProj5。此工程包含一个源程序文件RevMain5.cpp,该程序实现上述功能。但此程序运行有问题。请找出错误的地方,改正后将此程序调试正确。
注意:不得删行或增行,也不得更改程序结构。
文件RevMain5.cpp中的程序清单如下:
//RevMain5.cpp
#include<iostream>
#include<iomanip>
using namespace std;
int main( )
void sort(int array[],int n);
int data[10],*p,i;
cout<<"Input 10 numbers/n";
for (i=0; i<10; i++)
cin>>data [i];
cout<<"the origined array is:";
for (p=data;p<data+10;p++)
if((p-&data[0]) %5==0)
cout<<" /n";
cout<<setw (5) <<*p;
sort (data, 10);
cout<<"/n the present array is:";
for(p=data;p〈data+10;p++)
if((p-&data[0])%5==0) cout<<"/n";
cout<<setw (5)<<*p;
void sort(int array[],int n)
/* * * * * * * * *found * * * * * * * * * */
for(p1=array;p1<array+(n-1) ;p1++)
for (p2=p1+1 ;p2<array+n;p
[简答题]下列给定程序中,函数fun的功能是:用冒泡法对6个字符串按由小到大的顺序排列。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
#define MAXLINE 20
fun(char*pstr[6])
lnt i,j;
char *p;
for(i=O;i<5;i++)
/********found********/
for(j=i+l,j<6,j++)
if(strcmp(*(pstr+i)*(pstr+j))>0)
P=*(psfr+i);
/********found********/
*(pstr+i)=pstr+j;
*(pstr+j)=p;
void main( )
int i;
char*pstr[6],str[6][MAXLINE];
system("CLS");
for(i=O;i<6;i++)
pstr[i]=str[i];
printf("/nEnter 6 string(1 string at eachline):/n");
for(i=0;i<6;i++)
scanf("%s",pstr[i]);
fun(pstr);
printf("The strings after sorting:/n");
for(i=O;i<6;i++)
printf("%s/n"pstr[i]);
[填空题]以下程序的功能是:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。
例如,若一维数组中的数据是:
2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10
删除后,数组中的内容应该是:
2 3 4 5 6 7 8 9 10。
请填空。
#include <stdio.h>
#define N 80
int fun (int a[], int n)
int i,j=1;
for(i=1; i<n; i++)
if(a[j-1] (10) a[i])
a[j++]=a[i];
(11)
main( )
(int a[N]=(2, 2, 2, 3, 4, 4, 5, 6, 6, 6, 6, 7, 7, 8, 9, 9, 10, 10, 10], i, n=19;
printf("The original data: /n");
for(i=0; i<n; i++)printf("%3d", a[i]);
n=fun(a,n);
printf("/nThe data after deleted: /n");
fori=0; i<n; i++printf("%3d", a[i]); printf("/n/n");
[填空题]以下程序的功能是:删去一维数组中所有相同的数,使相同的数只剩一个。数组中的数已按由小到大的顺序排列,函数fun返回删除后数组中数据的个数。
例如,若一维数组中的数据是:
2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10
删除后,数组中的内容应该是:2 3 4 5 6 7 8 9 10。请填空。
#include <stdio.h>
#define N 80
int fun(int a[], int n)
int i,j=1;
for(i=1;i<n;i++)
if(a[j-1] a[i]) a[j++]=a[i];
;
main( )
int a[N]=2,2,2,3,4,4,5,6,6,6,6,7,7,8,9,9,10,10,10,i,n=19;
printf("The original data ://n");
for(i=0;i<n;i++) printf("%3d",a[i]);
n=fun(a,n);
printf("//nThe data after deleted ://n");
for(i=0; i<n; i++) printf("%3d",a[i]); printf("//n//n");
[简答题]下列给定程序中,函数fun的功能是:计算并输出high以内最大的10个素数的和。high的值由主函数传给fun函数。
例如,若high的值为10。,则函数的值为732。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<conio.h>
#include<scdio.h>
#include<math.h>
int fun(int high)
int sum=0,n=0,j,yes;
/********found********/
while((high>=2)&&(n<10)
yes=1;
for(j=2;j<=high/2;j++)
if(high%j==0)
/********found********/
yes=0;break
if(yes)
sum+=high;
n++;
high--;
return sum;
main( )
printf("%d/n",fun(100));
[填空题]下列给定程序中,函数fun( )的功能是:找出一个大于给定整数m且紧随m的素数,并作为函数值返回。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构.
试题程序:
#include <conio.h>
#include <stdio.h>
int fun( int m)
{ int i,k;
for (i=m+1; ;i++)
{ for (k=2;k<i;k++)
/*************found**************/
if (i%k!=0)
break;
/*************found**************/
if (k<i)
return(i);
}
}
main( )
{ int n;
clrscr ( );
printf("/nPlease enter n: ");
scanf ("%d", &n);
printf ("%d/n",fun(n));
}
[填空题]下面的程序用“冒泡”法将数组a中的10个整数按升序排列,请在 【9】 、 【10】 、 【11】 处将程序补充完整。
Option Base 1
Private Sub Command1_Click ( )
Dim a
a=Array (678, 45, 324, 528, 439, 387, 87, 875, 273,823)
For i= 【9】
For j= 【10】
If a(i) 【11】 a(j) Then
a1=a(i)
a(i)=a(j)
a (j) =a1
End If
Next j
Next i
For i=1 To 10
Print a(i)
Next i
End Sub
[填空题]请补充主函数main( ),该函数的功能是:把从键盘输入的3个整数按从小到大输出。
例如,输入“50 60 40”,结果输出“40 50 60”。
注意:部分源程序给出如下。
请勿改动main( )函数和其他函数中的任何内容,仅在横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void main( )
{
int x,y,z,s;
system("CLS");
printf("Input x,y,z/n");
scanf("%d%d%d",&x,&y,&z);
if(______)
{
s=x;
x=y;
y=s;
}
//交换x,y的值
if(______)
{
s=z;
z=x;
x=s;
}
//交换x,z的值
if(______)
{
s=y;
y=z;
z=s;
}
//交换z,y的值
printf("****the result****/n");
printf("from small to big:%d%d%d/n",x,y,z);
}