为什么运行不出正确结果?谁能告诉我
要求函数的功能是删除bb数组中值为y 的数,*n是bb中元素的个数fun函数是我编的
#include <conio.h>
#include <stdio.h>
#define M 20
void fun ( int bb[ ], int *n, int y )
{
int i,j;
for (i=*n-1;i>=0;i--)
if (bb[i]==y)
{
for (j=i;j<*n;j++)
{
bb[j]=bb[j+1];
(*n)--;
}
}
}
main( )
{ int aa[M], n, y, k;
clrscr();
printf( "\nPlease enter n : " ); scanf ( "%d", &n );
printf ( "\nEnter %d positive number :\n ", n );
for (k = 0; k<n; k++ ) scanf ("%d",&aa[k]);
printf ( "The original data is : \n" );
for (k = 0; k<n; k++ ) printf ("%5d",aa[k]);
printf ("\nEnter a number to deleted: " ); scanf ("%d", &y );
fun ( aa, &n, y );
printf ("The data after deleted %d : \n", y );
for ( k = 0; k < n; k++ ) printf ( "%4d ", aa[ k ] );
printf( "\n" );
谢谢了