C/C++ 刪除陣列中指定的元素,寫的不是很完整。

 

範例碼(一):

// test.cpp : 定義主控台應用程式的進入點。
//

#include "stdafx.h"
#include 
#include 
#include 
#include 

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	int a[6]={10,20,30,40,50,60};
	int b=sizeof(a)/4;
	char str[10];
	memset(str,0x00,sizeof(str));
	cout<<"輸入要刪除的陣列元素索引=";
	gets(str);
	int c=atoi(str);
	a[c]=0x00;

	for(int i=0 ; i < b ; i++)
	{
		if(a[i] != 0x00)
		{
			if(i == 0)
			{
				cout<<a[i];
			}
			else
			{
				cout<<","<<a[i];
			}
		}
	}
	cout<<endl;
		return 0;
}


執行結果:

201306022132  

arrow
arrow
    全站熱搜

    mitblog 發表在 痞客邦 留言(0) 人氣()