请编写函数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。
注意:部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数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。
注意:部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数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(【 】)
;
else
{
【 】;
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 int fun(int a[], int n) { int i,j=1; for(i=1;i <n;i++) if(a[j-1] (1) a[i]) a[j++]="a[i];" return (2) ; } 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;" printf(“%d ”,a[i]); n="fun(a,n);" printf("\nthe data after deleted: \n");>
例如,一维数组中的原始内容为:1,2,3,4,5,6,7,8,9,10:p的值为3。移动后,一维数组中的内容应为:5, 6, 7, 8, 9, 10, 1, 2, 3,4。
注意:部分源程序在文件PROGl.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数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);
}
A.是死循环
B.循环执行两次
C.循环执行一次
D.有语法错误
A.'A'<=cl<='Z'
B.(cl>=A)&&(cl<=Z)
C.('A'>=cl)||('Z'<=cl)
D.(cl>='A')&&(cl<='Z')
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!