早教吧 育儿知识 作业答案 考试题库 百科 知识分享

3.定义一个函数,功能是删除整型数组中指定的数。如:数组中的数为:1、4、8、9、7、7、9、0要删除的数

题目详情
3.定义一个函数,功能是删除整型数组中指定的数。如:数组中的数为:1、4、8、 9、7 、7、9、0 要删除的数
▼优质解答
答案和解析
#include
using namespace std;
//如何处理删除数值后的数组,没有说明白
//是以0补位还是重新开辟一个新的数组呢
//为了演示数组元素个数的变化,这个函数只得多一个参数
void delNum(int[],int&,int);
int main()
{
int count=14;//数组的成员个数
int array[]={1,4,8,9,7,7,9,0,0,1,0,4,0,8};
cout< for(int n=0;n<14;n++) cout< cout< cout< int input;
cin>>input;
delNum(array,count,input);
cout< for(int n=0;n cout< return 0;
}
void delNum(int array[14],int& count,int num)
{
for(int n=0;n {
if (array[n]==num)
{
for(int i=n;i count--;
n--;
}
}
}