난수발생함수에서..
나래
2023.04.01
난수발생함수를 이용해서 간단한 프로그램을 짜려고하는데요..
1-8까지의 난수가 화면에2번씩 출력되게하고싶은데..
어떻게해야할지몰라서요..
답변좀 부탁드립니다~(__)
#include stdio.h
#include stdlib.h
#include time.h
void card();
int main()
{
card();
}
void card()
{
int i;
int card;
int flag;
int count=0;
int couple[16]={0};
srand((unsigned)time(NULL));
while(count16)
{
card=rand()%16+1;
for (i=0,flag=0;icount ;i++ )
{
if (couple[i]==card)
{
flag=1;
break;
}
}
if (flag==0)
{
couple[count++]=card;
printf(%2d,card);
if (count%4==0)
{
printf(\n);
}
}
}
}
-
권시크
그방법말고 조건을 추가해서 하는 방법은 없나요??ㅠㅠ