Created
November 3, 2014 23:00
-
-
Save syntaxerrormmm/ccd028fce812e49d7d5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, char *argv[]) { | |
int numeri[100]; | |
int i = 0; | |
int n = 0; | |
int contatore = 0; | |
int prec, succ; | |
while (i < 100 && numeri[i] != 1000) { | |
i++; | |
scanf("%d", &numeri[i]); | |
} | |
// Devo scartare l'ultimo caso, che è necessariamente 1000 | |
i--; | |
while (n <= i) { | |
// Escludo il caso in cui n = 0: non c'è caso precedente. | |
prec = n - 1; | |
if (prec >= 0) { | |
if ( | |
(numeri[prec] * numeri[prec] == numeri[n]) || | |
(numeri[n] * numeri[n] == numeri[prec]) ) | |
contatore++; | |
} | |
// Verifico anche l'elemento successivo. | |
succ = n + 1; | |
if (succ <= i) { | |
if ( | |
(numeri[n] * numeri[n] == numeri[succ]) || | |
(numeri[succ] * numeri[succ] == numeri[n]) ) | |
contatore++; | |
} | |
n++; | |
} | |
printf("%d\n", contatore); | |
return 0; | |
} | |
// vim:sts=3:sw=3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment