소스코드
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <time.h>
int _tmain(int argc, _TCHAR* argv[])
{
srand((unsigned)time(NULL));
int array[10];
int a = 0;
int tmp = 0;
int count = 0;
while (a < 10)
{
if (a == 0)
{
array[0] = rand() % 10;
a++;
}
else
{
tmp = rand() % 10;
count = 0;
for (int i = 0; i < 10 ; i++)
{
if (array[i] == tmp)
{
count++;
}
}
if (count == 0)
{
array[a] = tmp;
a++;
}
}
}
for (int i = 0; i < 10; i++)
{
cout << array[i] << endl;
}
return 0;
}
출력결과
'C++' 카테고리의 다른 글
배열의 디폴트 값은 쓰레기 값 (0) | 2011.06.04 |
---|