如何使用 C 语言将一个整数与一个由十个整数组成的数组进行比较,以找出单个整数是否包含在数组中?如果原始问题不清楚,我深表歉意,而滑动等于我想输出 PORTD=0b10000000 的数组中的任何数字。谢谢!
short a[10]={10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; //Array of accepted passwords.
short array[10];
int i;
for(i=0; i<10; i++){
array[i]=a[i];
}
srand(clock());
while(1){
int swipe=rand() % 20; /* Simulated code read from card swipe, in this
* instance we used a random number between
* 1 and 20.*/
for(i=0; i<10; i++){
if(swipe == array[i]) {
PORTD=0b10000000;
} else {
PORTD=0b00001000;
} //If swiped code evaluates as one of the approved codes then set PORTD RD7 as high.
}
char Master=PORTDbits.RD7;
这似乎已经解决了......感谢您的所有帮助!
for(i=0; i<10; i++){
if(swipe == array[i]) {
PORTD=0b10000000;
break;
} else {
PORTD=0b00001000;
}
}