Skip to content

Instantly share code, notes, and snippets.

@syntaxerrormmm
Created November 3, 2014 23:00
Show Gist options
  • Save syntaxerrormmm/ccd028fce812e49d7d5e to your computer and use it in GitHub Desktop.
Save syntaxerrormmm/ccd028fce812e49d7d5e to your computer and use it in GitHub Desktop.
#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