#include <_stdio.h_>
#include <_stdlib._h>
#include <_time._h>
#define MAX 52
#define NOMAX 100
void get_card( int *add );
int find_card(int *add, int no );//回傳有沒有,在第幾個, 0 = 沒有
int main() {
int i = 0, no; //i=第幾張牌
int card[MAX]={0}; https://www.onlinegdb.com/myfiles //[0、、、51]
while(1){
get_card( card ); //傳送card 位址給 get_card()
for( i=0; i< MAX; i++ ) {
if ( i % 10 == 0) printf( "\n" ); //10張就斷行
printf( "-,", card[i]); // 0 用空白取代
}
printf( "\n請輸入欲找尋數值 =" );
scanf("%d", &no );
i = find_card( card, no ); //傳送card 位址給 sort_card()
if ( i == 0 ) printf( "\n找不到此數值\n" );
if ( i > 0 ) printf( "\n找到此數值,在第[%d] =%d \n", i, card[i-1] );
}
return 0;
}
//--------------------------------------------
int find_card( int *add, int no ) {
int i;
int rc = 0; //假設找不到
for ( i=0; i
if ( add[i] == no ) rc = i+1;//找到了
}
return rc;
}
//--------------------------------------------
void get_card( int *add ) {
int done[NOMAX] = {0}, busy = 1;
int i = 0; //i=發到第幾張牌
srand( time(NULL) ); //clock() );
while ( 1 ) {
busy = 1; //預設一直抓
while ( busy ) {
int n = rand() % NOMAX + 1 ; // (0~51) + 1 = 1~52
if ( done[n] == 0 ) { //判斷這張牌 有沒有 發過??
done[n] = 1; //表示這張牌已被使用
add[i] = n; //發出去這張牌
busy = 0;
}
}
if ( ++i >= MAX ) break;
}
}