删除数组中指定的数

 环境:Win10,VS2010

#include<iostream>
using namespace std;

void main()
{
 int a[100],i=0,k,j,l,m,cha,gs;

 cout<<"请输入数列:";
 while(1)
 {
 cin>>a[i];
 if(a[i]==0) break;
 i++;
 }

 cout<<"输入要查找的数:";
 cin>>cha;

 for(k=0;k<=i-1;k++) 
 {
	if(a[k]==cha) 
	{
		for(j=k;j<i-1;j++)
		{
			a[j]=a[j+1];
		}
		i--;
		k--;
	 }
 }
 
 cout<<"处理结果";
 for(l=0;l<=i-1;l++) 
 cout<<a[l]<<" ";
 system("pause");
}

猜你喜欢

转载自blog.csdn.net/a12336487213/article/details/83213639