answersLogoWhite

0


Best Answer

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.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How could you count a number how many times present in an array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you count the number of elements in an array using PHP?

Using the function "count". <?php $foo = array("John", "Jacob", "Jingleheimer", "Schmidt"); echo count($foo); // <-- outputs the number 4 ?>


How can you calculate the average and median in perl by subroutine?

<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>


How do you find the average of rows and columns in a 2d array in java?

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.


How you count lentgh of string without using strlen?

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.


Write a 'c' program to accept 'n' numbers from user store these number into an array count the numbers of occurrence of each numbers?

#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

Related questions

How do you count the number of elements in an array using PHP?

Using the function "count". <?php $foo = array("John", "Jacob", "Jingleheimer", "Schmidt"); echo count($foo); // <-- outputs the number 4 ?>


Program to count the number of numbers in an array using 8085 microprocessor?

A program which is used to count the number of numbers in an array using a 8085 microprocessor is known as a assembly language program.


How can you calculate the average and median in perl by subroutine?

<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>


What is the highest number we can count to?

There is no such number. If we could count to any particular number, then we can always count to the next one. And then the next. And so on.


Do you say 'count the stars' or 'count the number of stars'?

Both could be correct it depends on the situation. If you could count the stars how many so you think there are? Count the number of stars you can see out the window.


How do you find the size of an array in PHP?

To find the size of an array in PHP you can either use the count() function or the sizeof() function as they will produce the same result. <?php $array = array(1, 2, 3, 4, 5, 6, 7); echo count($array); // outputs 7 echo sizeof($array); // outputs 7 ?>


How do you count the vowels in a string using PHP?

build an array of vowels then do a foreach on the array and then explode the string on the array value and the answer is -1 of the result


What is the total number of receptors present in a human body?

too many to count


Write a C programme to count the number of vowals present in your name?

abhimanyu


How do you count the number of elements in a compound?

To count the number of elements in a compound, you can identify the different elements present by looking at the chemical formula. Each element is represented by a unique symbol (e.g., H for hydrogen, O for oxygen). Count the number of unique elements present in the compound to determine the total number of elements.


How do you count how many results are in a PHP array?

To find out how many results there are in a PHP array all you need to do is use the function count() like I have shown you in the example below.


The maximum number of records you might want to store in an array is defined as MAX When using 0 based indexing what index will reference the last allocated position of an array of size MAX?

If all elements of the array are in use then the last record is referred to as MAX-1. If you are using a count variable to remember how far into the array you are using then this variable will keep track of the last allocated value in the array.