#include <stdio.h>
char *input_argv[] = { "prog.c", "11", "5", "7", "11", "22" }; // al posto di argv[]
int input_argc = sizeof (input_argv) / sizeof (input_argv[0]); // al posto di argc
int
ricercaseq (int lista[], int x, int a, int z)
{
int i;
// Scandisce l'array alla ricerca dell'elemento.
for (i = a; i <= z; i++)
{
if (x == lista[i])
{
return i;
}
}
// La corrispondenza non รจ stata trovata.
return -1;
}
int
main (int argc, char *argv[])
{
int lista[argc - 2];
int x;
int i;
// Acquisisce il primo argomento come valore da cercare.
sscanf (input_argv
[1], "%i", &x
);
// Considera gli argomenti successivi come gli elementi
// dell'array da scandire.
for (i = 2; i < input_argc; i++)
{
sscanf (input_argv
[i
], "%i", &lista
[i
-2]); }
// Esegue la ricerca.
i = ricercaseq (lista, x, 0, input_argc - 2);
// Emette il risultato.
printf ("%i si trova nella posizione %i\n", x
, i
);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgpjaGFyICppbnB1dF9hcmd2W10gPSB7ICJwcm9nLmMiLCAiMTEiLCAiNSIsICI3IiwgIjExIiwgIjIyIiB9OyAgICAgIC8vIGFsIHBvc3RvIGRpIGFyZ3ZbXQppbnQgICBpbnB1dF9hcmdjICAgPSBzaXplb2YgKGlucHV0X2FyZ3YpIC8gc2l6ZW9mIChpbnB1dF9hcmd2WzBdKTsgIC8vIGFsIHBvc3RvIGRpIGFyZ2MKCmludApyaWNlcmNhc2VxIChpbnQgbGlzdGFbXSwgaW50IHgsIGludCBhLCBpbnQgeikKewogICAgaW50IGk7CgogICAgLy8gU2NhbmRpc2NlIGwnYXJyYXkgYWxsYSByaWNlcmNhIGRlbGwnZWxlbWVudG8uCgogICAgZm9yIChpID0gYTsgaSA8PSB6OyBpKyspCiAgICAgIHsKICAgICAgIGlmICh4ID09IGxpc3RhW2ldKQogICAgICAgICAgewogICAgICAgICAgICByZXR1cm4gaTsKICAgICAgICAgIH0KICAgICAgfQoKICAgIC8vIExhIGNvcnJpc3BvbmRlbnphIG5vbiDDqCBzd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