// Q.2
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#define DATA_MAX 50
int linear_search(int data[],int key,int num)
{
int i;
for (i = 0; i < num; i++) {
if (data[i] == key) return i;
}
return -1;
}
void random_data(int data[],int num)
{
int i, n;
for (i = 0; i < num; i++) {
data[i] = -1;
}
for (i = 0; i < num; ) {
n
= (int)((double)num
*rand()/(1.0+RAND_MAX
)); if (data[n] != -1) continue;
data[n] = i;
i++;
}
}
int main()
{
int data[DATA_MAX];
int num, key, i;
printf("データの数(MAX:%d)>", DATA_MAX
); random_data(data, num);
for (i = 0; i < num; i++) {
printf("%d %d\n", i
, data
[i
]); }
i = linear_search(data, key, num);
if (i == -1) {
} else {
}
return 0;
}
Ly8gUS4yCiNkZWZpbmUgX0NSVF9TRUNVUkVfTk9fV0FSTklOR1MKI2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCiNkZWZpbmUgREFUQV9NQVggNTAKCmludCBsaW5lYXJfc2VhcmNoKGludCBkYXRhW10saW50IGtleSxpbnQgbnVtKQp7CglpbnQgaTsKCglmb3IgKGkgPSAwOyBpIDwgbnVtOyBpKyspIHsKCQlpZiAoZGF0YVtpXSA9PSBrZXkpIHJldHVybiBpOwoJfQoJcmV0dXJuIC0xOwp9Cgp2b2lkIHJhbmRvbV9kYXRhKGludCBkYXRhW10saW50IG51bSkKewoJaW50IGksIG47CgoJZm9yIChpID0gMDsgaSA8IG51bTsgaSsrKSB7CgkJZGF0YVtpXSA9IC0xOwoJfQoJZm9yIChpID0gMDsgaSA8IG51bTsgKSB7CgkJbiA9IChpbnQpKChkb3VibGUpbnVtKnJhbmQoKS8oMS4wK1JBTkRfTUFYKSk7CgkJaWYgKGRhdGFbbl0gIT0gLTEpIGNvbnRpbnVlOwoJCWRhdGFbbl0gPSBpOwoJCWkrKzsKCX0KfQoKaW50IG1haW4oKQp7CglpbnQgZGF0YVtEQVRBX01BWF07CglpbnQgbnVtLC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