1 | initial version |
Here's an example code that counts the total number of occurrences of a particular element in an array using C Language:
#include <stdio.h>
int main() {
int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 5};
int count = 0;
int numberToFind = 5;
int i;
for(i=0; i<10; i++) {
if(arr[i] == numberToFind) {
count++;
}
}
printf("The total count of %d is %d\n", numberToFind, count);
return 0;
}
In this example, we have an array arr
that contains 10 elements. We want to find the total number of times the value 5
appears in the array.
We initialize a variable count
to 0
and a variable numberToFind
to 5
. Then we loop through each element in the array and check if it's equal to numberToFind
. If it is, we increment the count
variable. After looping through the entire array, we print the result.
The output of this code will be:
The total count of 5 is 2