Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Find Repeated Number of an Array

Status
Not open for further replies.

creative_35

Full Member level 1
Joined
Apr 10, 2006
Messages
95
Helped
9
Reputation
18
Reaction score
3
Trophy points
1,288
Location
Under Mango Tree
Activity points
2,032
Hi friends,
How can I find out repeated number of an array in CCSC.
For example

We have an array of say 15 elements
Code:
a[15]={25,30,40,60,12,90,40,25,75,12,65,40,55,40,15}
The more repeated element is 40. so the result should be
Code:
result = 40
number of times repeated =4

Thanks in advans.
 

this should be something like this; hope you understand the ideea...
just translate the pseudocode in your needed language

Code:
consider another array b[15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} // this second array is for algorithm speeding

count_max:=0;
for i:=1 to 15 do
 if b[i]=0 then
   count=1;
   for j:=i+1 to 15 do
     begin
      if (a[i]=a[j]) then
       begin
         b[j]:=1;
         count:=count+1;
         current_no:=a[i];
       end
       if (count>count_max) then
        begin
         count_max:=count;
         max_no:=a[i];
        end
     end
  result:=max_no;
  repeated_times:=count;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top