Created
October 30, 2016 15:31
-
-
Save frabert/244da42e6ea533b18b6136a01d9fc0c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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