更多"请编写函数fun, 函数的功能是: 删去一维数组中所有相同的数, 使之"的相关试题:
[简答题]请编写函数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。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio. h>
#define N 80
int fun(int a[], int n)
main ( )
int a[N]= 2,2,2,3,4,4,5,6,6,6,6,7,7,
8,9,9,10,10,10,10, i, n=20;
printf ("The original data : /n");
for(i=0; i<n; i++)
printf ("%3d", a [i] );
n=fun (a, n);
printf("/n/nThe data after deleted
: /n");
for(i=0; i<n; i++)
printf ("%3d", a [i] );
printf ("/n/n");
[填空题]请补充函数fun( ),该函数的功能是:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。
例如,若一维数组中的数据是:1,1,1,2,2,2,3, 4,4,5,5,6,6,7,7,8,9,9,10,10。
删除后,数组中的内容应该是:1,2,3,4,5,6,7, 8,9,10。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#define N 80
int fun(int a[],int n)
{
int i, t,j=0;
t=a[0];
for(i=1;i<n;i++)
if( 【1】 )
;
else
{
【2】 ;
t=a[i];
}
a[j++]=t;
return j;
}
main( )
{
int a[N]={1,1,2,2,2,3,4,4,5,5,6,6,6,
7,7,8,9,9,10,10},i,n=20;
printf("The original data:/n");
for(i=0; i<n; i++)
printf("%4d",a[i]);
n=fun(a,n);
printf("/n/nThe data after deleted ;
/n");
for (i=0;i<n;i++)
printf("%4d",a[i]);
printf("/n");
}
[填空题]以下程序的功能是:删去一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。
例如,若一维数组中的数据是:
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
intfun(int a[],int n)
{int i,j=1;
for(i=1;i<n;i++)
if(a[j-1] [8] a[i])
a[j++]=a[i];
[9] ;
}
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返回删除后数组中数据的个数。
例如,若一维数组中的数据是:
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( ),该函数的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从0到p(p≤n-1)的数组元素平移到数组的最后。
例如,一维数组中的原始内容为1,2,3,4,5,6,7, 8,9,10,11,12,13,14,15,p的值为3。移动后,一维数组中的内容应为5,6,7,8,9,10,11,12,13,14,15, 1, 2, 3, 4。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
#define N 80
void fun(int *w, int p, int n)
{
}
main ( )
{
int a[N]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int i, p, n=15;
printf("The original data:/n");
for(i=0;i<n;i++)
printf("%3d",a[i]);
printf("/n/nEnter p: ");
scanf("%d",&p);
fun(a,p,n);
printf("/nThe data after moving:/n");
for(i=0;i<n;i++)
printf("%3d",a[i]);
printf("/n/n");
}
[简答题]请编写函数fun( ),该函数的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从p到n-1(p≤n-1)的数组元素平移到数组的前面。
例如,一维数组中的原始内容为1,2,3,4,5,6,7, 8,9,10,11,12,13,14,15,p的值为6。移动后,一维数组中的内容应为7,8,9,10,11,12,13,14,15,1,2,3,4,5,6。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#define N 80
void fun(int *w,int p,int n)
main( )
int a[N]=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15;
int i,p,n=15;
printf("The original data:/n");
for(i=0;i<n;i++)
printf("%3d",a[i]);
printf("/n/nEnter p:");
scanf("%d",&p);
fun(a,p,n);
printf("/nThe data after moving:/n");
for(i=0;i<n;i++)
printf("%3d",a[i]);
printf("/n/n");
[简答题]请编写函数fun( ),该函数的功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从p~n-1(p<n-1)的数组元素平移到数组的前面。
例如,一维数组中的原始内容为1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, P的值为6。移动后,一维数组的内容应为7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
[试题源程序]
#inciude <stdio.h>
#define N 80
void fun(int *w, int p, int n)
main( )
int a[N]=(i, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
int i, P, n=15;
printf("The original data:/n");
for(i=0; i<n; i++)
printf("%3d", a[i]);
printf("/n/nEnter p: ");
scanf("%d", &p);
fun(a, P, n);
printf("/nThe data after moving:/n");
for(i=0; i<n; i++)
printf("%3d", a[i]);
printf("/n/n");
[简答题]请编写函数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";
[简答题]请编写函数fun( ),该函数的功能是:将M行N列的二维数组中的数据,按行的顺序依次放到一维数组中,一维数组中数据的个数存放在形参n所指的存储单元中。
例如,若二维数组中的数据为:
33 33 33 33
44 44 44 44
55 55 55 55
则一维数组中的内容应该是33 33 33 33 44 44 44 AA, 55 55 55 55
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio. h>
void fun (int (*s)[10], int *b, int *n,
int mm, int nn)
{
}
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 ;
printf ("The matrix: /n" );
for (i=0; i<3; i++)
{for (j+0; j<4; j++)
printf ("%3d",w[i] [j] );
printf ("/n");
}
fun (w,a, &n, 3, 4);
printf ("The A array: In");
for(i=0; i<n; i++)
printf ("%3d", a [i] );
printf ("/n/n");
}
[简答题]请编写函数fun, 函数的功能是: 移动一维数组中的内容; 若数组中有n个整数, 要求把下标从0到p(含p,p小于等于n-1)的数组元素平移到数组的最后。 例如, 一维数组中的原始内容为: 1,2,3,4,5,6,7,8,9,10; p的值为3。移动后, 一维数组中的内容应为: 5,6,7,8,9,10,1,2,3,4。 注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 给定源程序: #include #define N 80 void fun(int *w, int p, int n) { } main( ) { int a[N]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; int i,p,n=15; printf("The original data:/n"); for(i=0; i
[简答题]请编写函数fun( ),该函数的功能是判断字符串是否为回文,若是则函数返回1,主函数中输出YES:否则返回0,主函数中输出NO。回文是指顺读和倒读都一样的字符串。
例如:字符串LEVEL是回文,而字符串123312就不是回文。
注意;部分源程序已存在文件test26_.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。
文件test26_2.cpp的内容如下:
#include<iostream.h>
#include<stdio.h>
#define N 80
int fun(char*str)
void main( )
char s[N];
cout<<"Enter a string:"<<endl;
getss);
cout<<"/n/n";
puts(s);
if(fun(s))
cout<<"YES/n";
else
cout<<"NO/n";
[简答题]简单应用题 请编写函数fun( ),该函数的功能是判断字符串是否为回文,若是则函数返回1,主函数中输出YES;否则返回0,主函数中输出NO。回文是指顺读和倒读都一样的字符串。 例如:字符串LEVEL是回文,而字符串123312就不是回文。 注意:部分源程序已存在文件kt11_2.cpp中。 请勿修改主函数main和其他函数中的任何内容,仅在函数fun的花括号中填写若干语句。 文件kt11_2.cpp的内容如下: #include #include #defineN80 intfun(char*str) { } voidmain( ) { chars[N]; cout<<"Enterastring:"<
[简答题]请编写函数fun( ),该函数的功能是:计算n门课程的平均分,计算结果作为函数值返回。
例如x有5门课程的成绩是90.5,72,80,61.5,55,则函数的值为71.80。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
float fun (float *a, int n)
main ( )
float score[30]=(90.5,72,80,61.5,55,
aver;
aver=fun(score, 5);
printf("/nAverage score is: %5.2f
/n",aver);
[简答题]请编写函数fun( ),该函数的功能是:统计各年龄段的人数。N个年龄通过调用随机函数获得,并放在主函数的age数组中。要求函数把0至9岁年龄段的人数在d[0]中,把10至19岁年龄段的人数放在d[1]中,把20至29岁年龄段的人数放在 d[2]中,依次类推,把100岁(含100)以上年龄的人数都放在d[10]中。结果在主函数中输出。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio. h>
# define N 50
# define M 11
void fun(int *a, int *b)
double rnd( )
static t=29, c=217,m=1024, r=0;
r= (r*t+c)%m;
return ((double) r/m);
main ( )
int age[N], i,d[M];
for(i=0; i<N; i++)
age [i]= (int) (i15*rnd ( ));
/*产生一个随机的年龄数组*/
printf ("The original data : /n");
for(i=0; i<N; i++)
printf((i+l)%10= =07 "%4d/n":"%4d",
age[i]); /*每行输出10个数* /
printf ("/n/n");
fun (age, d);
for(i=0; i<l0; i++)
printf("%4d---%4d :%4d/n", i*l0,
i*10+9, d[i] );
printf("Over 100 : %4dkn",d[10]).;
[简答题]请编写函数fun( ),该函数的功能是:统计一行字符串中单词的个数,作为函数值返回。一行字符串在主函数中输入,规定所有单词由小写字母组成,单词之间有若干个空格隔开,一行的开始没有空格。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<string. h>
# include<stdio, h>
#define N 80
int fun (char *s)
{
}
main ( )
{
char line [N];
int num=0;
printf ("Enter a string: /n ");
gets (line);
num=fun (line);
printf ("The number of word is: %d/n/n ",
num);
}