Skip to content

Instantly share code, notes, and snippets.

@frabert
Created October 30, 2016 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frabert/244da42e6ea533b18b6136a01d9fc0c7 to your computer and use it in GitHub Desktop.
Save frabert/244da42e6ea533b18b6136a01d9fc0c7 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int conta(int a[], int elem, int init, int end) {
int tmp = 0;
int i;
for(i = init; i < end; i++) {
if(a[i] == elem) tmp++;
}
return tmp;
}
// In questo caso controllo se un dato array contiene o no un elemento
int main(void) {
int array[5] = {1,6,7,3,9};
int e = 7;
int num = conta(array, e, 0, 5);
if(num > 0) {
printf("L'array contiene l'elemento %d\n", e);
} else {
printf("L'array non contiene l'elemento %d\n", e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment