c语言:这个怎么做?? 帮帮忙哦! 先谢了!

2. 打开程序Cprog012.C,完成其中的函数fun2(int a[ ], int n, int b[ ], int c[ ]),实现:
(1)将数组a中大于-20的元素,依次存放到数组b中;
(2)将数组b中的元素按照从小到大的顺序存放到数组c中;
(3)函数返回数组b中的元素个数。
#include <string.h>
#include <conio.h>
#include <math.h>
#include <stdio.h>
int fun2(int a[],int n,int b[],int c[])
{
/**/

/**/
}
void main()
{ int n = 10, i, nb;
int aa[10] = {12, -10, -31, -18, -15, 50, 17, 15, -20, 20};
int bb[10], cc[10];
clrscr();
printf("There are %2d elements in aa.\n", n);
printf("They are: ");
for(i=0; i<n; i++) printf("%6d", aa[i]);
printf("\n");
nb = fun2(aa, n, bb, cc);
printf("Elements in bb are: ");
for (i=0; i<nb; i++) printf("%6d", bb[i]);
printf("\n");
printf("Elements in cc are: ");
for(i=0; i<nb; i++) printf("%6d", cc[i]);
printf("\n");
printf("There are %2d elements in bb.\n", nb);

VS2005编译通过,希望对你有帮助!
int fun2(int a[],int n,int b[],int c[])
{
int i,j,temp;
int index=0;

for(i = 0; i < n; i++)
{
if(a[i] > -20)
{
c[index]=b[index]=a[i];
index++;
}
}

for(i=0;i<index;i++)
{
for (j=i+1;j<index;j++)
{
if(c[i]>c[j])
{
temp=c[i];
c[i]=c[j];
c[j]=temp;
}
}
}

return index;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-04-25
帮顶、、、、、、、、、、
第2个回答  2012-04-25
不知
相似回答