You can do this with a simple for loop counting through the array and increasing a tally each time you sought number is hit.:
tally = 0
for each element in the array {
if this element has the value we want{
tally = tally + 1
}
}
output the taly
In PHP for example, this could be done like so:
$tally = 0;
foreach($foo as $bar){
if($bar == $value_sought) $tally++;
}
echo $tally;
where "$foo" is the array you're serching and $value_sought is the number you're looking for.
Chat with our AI personalities
Using the function "count". <?php $foo = array("John", "Jacob", "Jingleheimer", "Schmidt"); echo count($foo); // <-- outputs the number 4 ?>
<pre> sub average { @_ 1 or die ('Sub usage: $median = median(\@array);'); my ($array_ref) = @_; my $count = scalar @$array_ref; # Sort a COPY of the array, leaving the original untouched my @array = sort { $a <=> $b } @$array_ref; if ($count % 2) { return $array[int($count/2)]; } else { return ($array[$count/2] + $array[$count/2 - 1]) / 2; } } </pre>
You add up all the array elements, then divide by the number of elements. You can use a nested for() loop in Java; inside the inner for() loop, you can both increase a counter (to count how many elements there are), and add to a "sum" variable.
Basically in C language string is NULL (0x00) byte ending char array. So in order to find out the length of the string you need to count all elements in array until you reach NULL. But that is what strlen does. There are two links with information about strlen implementation and null-terminated strings.
#include<stdio.h> #include<conio.h> void main() { int a[10],i,j,k; int count=1,num[10],pos=0; clrscr(); printf("Enter the Array Element "); for(i=0;i<10;i++) { scanf("%d",&a[i]) ; }//close the for loop for(i=0;i<10;i++) { count=1,pos++; for(j=0;j<10;j++) { if(a[i]==a[j]) { for(k=j;k<10;j++) a[k]=a[k+1] }//close the if count++; }//close the for loop num[pos] = count; }//close the for loop for(i=0;i<pos;i++) printf("Repeted Number of IN Arrary %d",num[i]); }//close the main