SlideShare a Scribd company logo
Find the frequency of presence of an
element in an array???
Agenda
1. Program in c++
2. Array declaration and definition
3. Enter the element to be counted
4. Counter or freq variable declaration
5. Print the particular element along with a
number how many times that number gets
repeated in the given array
Logic
• Given array for example:
• arr[]={1,2,3,2,3,2,2}
• Element to be find is 2 (No.of times repeated)
• How to find the repeated element present in an
array
• Soln:Using for loop:
• for (i=0;i<n;i++)
• if(a[i]==ele)(main logic)
• counter++;
Let’s See Practically by writing the
program
• #include<iostream.h>
• #include<conio.h>
• void main()
• {
• int a[100],ele,n,i,freq;
• clrscr();
• cout<<"Enter the size of array"<<endl;
• cin>>n;
• cout<<"Enter the elements of array"<<endl;
• for(i=0;i<n;i++)
• {
• cin>>a[i];
• }
• cout<<"Enter the element to be counted"<<endl;
• cin>>ele;
• freq=0;
• for(i=0;i<n;i++)
• {
• if(a[i]==ele)
• {
• freq=freq+1;
• }
• }
• cout<<"Frequency of "<<ele<<" is "<<freq;
• getch();
• }
Thank You

More Related Content

What's hot (20)

DOCX
Python lab manual all the experiments are available
Nitesh Dubey
 
PPT
Coherence SIG: Advanced usage of indexes in coherence
aragozin
 
PPTX
Arrays.pptx
Shweta Bhatia
 
PDF
Algorithms python arraylistmatrix
Faculty of Science , portsaid Univeristy
 
PDF
1D Array
A. S. M. Shafi
 
PPT
Grand Central Dispatch
Joachim Bengtsson
 
PDF
CBSE Python List Assignment
Amit Sethi
 
PPT
List in java
nitin kumar
 
PPTX
IGraph a tool to analyze your network
Pushpendra Tiwari
 
PDF
Oot practical
Vipin Rawat @ daya
 
PPTX
Algorithm analysis and design
Megha V
 
DOCX
Bubble in link list
university of Gujrat, pakistan
 
PPTX
Arrays in Data
Afzal Badshah
 
DOCX
Write a program that calculate the no of prime no,even and odd no.
university of Gujrat, pakistan
 
PDF
Concept of Stream API Java 1.8
InnovationM
 
PPTX
Favor composition over inheritance
Kochih Wu
 
PPTX
Java programs
FathimaLidiya
 
PPTX
F# array searching
DrRajeshreeKhande
 
PDF
Gdg almaty. Функциональное программирование в Java 8
Madina Kamzina
 
PDF
FS2 for Fun and Profit
Adil Akhter
 
Python lab manual all the experiments are available
Nitesh Dubey
 
Coherence SIG: Advanced usage of indexes in coherence
aragozin
 
Arrays.pptx
Shweta Bhatia
 
Algorithms python arraylistmatrix
Faculty of Science , portsaid Univeristy
 
1D Array
A. S. M. Shafi
 
Grand Central Dispatch
Joachim Bengtsson
 
CBSE Python List Assignment
Amit Sethi
 
List in java
nitin kumar
 
IGraph a tool to analyze your network
Pushpendra Tiwari
 
Oot practical
Vipin Rawat @ daya
 
Algorithm analysis and design
Megha V
 
Bubble in link list
university of Gujrat, pakistan
 
Arrays in Data
Afzal Badshah
 
Write a program that calculate the no of prime no,even and odd no.
university of Gujrat, pakistan
 
Concept of Stream API Java 1.8
InnovationM
 
Favor composition over inheritance
Kochih Wu
 
Java programs
FathimaLidiya
 
F# array searching
DrRajeshreeKhande
 
Gdg almaty. Функциональное программирование в Java 8
Madina Kamzina
 
FS2 for Fun and Profit
Adil Akhter
 

Similar to Frequency count of the Element in an array (13)

PDF
TffffThe program needs to be in C++ and part 1 of the assignment i.pdf
arri2009av
 
PPTX
Arrays_in_c++.pptx
MrMaster11
 
PDF
Starting Out with C++ from Control Structures to Objects 8th Edition Gaddis S...
quezjgcgkf1379
 
PDF
Starting Out with C++ from Control Structures to Objects 8th Edition Gaddis S...
savarsewel4f
 
PDF
Below is the assignment description and the file I have written..pdf
info673628
 
PDF
Starting Out with C++ from Control Structures to Objects 8th Edition Gaddis S...
ensalough
 
PPTX
Programming data structure concept in array ppt
seetha394884
 
PDF
Searching
A. S. M. Shafi
 
DOCX
Arrays
George Scott IV
 
PDF
Array (data structure using c++).PPT presentation
minedrugs777
 
PDF
Data structures arrays
maamir farooq
 
PPT
lecture7.ppt
EdFeranil
 
PPT
its arrays ppt for first year students .
anilkumaralaparthi6
 
TffffThe program needs to be in C++ and part 1 of the assignment i.pdf
arri2009av
 
Arrays_in_c++.pptx
MrMaster11
 
Starting Out with C++ from Control Structures to Objects 8th Edition Gaddis S...
quezjgcgkf1379
 
Starting Out with C++ from Control Structures to Objects 8th Edition Gaddis S...
savarsewel4f
 
Below is the assignment description and the file I have written..pdf
info673628
 
Starting Out with C++ from Control Structures to Objects 8th Edition Gaddis S...
ensalough
 
Programming data structure concept in array ppt
seetha394884
 
Searching
A. S. M. Shafi
 
Array (data structure using c++).PPT presentation
minedrugs777
 
Data structures arrays
maamir farooq
 
lecture7.ppt
EdFeranil
 
its arrays ppt for first year students .
anilkumaralaparthi6
 
Ad

Recently uploaded (20)

PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
community health nursing question paper 2.pdf
Prince kumar
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Ad

Frequency count of the Element in an array

  • 1. Find the frequency of presence of an element in an array???
  • 2. Agenda 1. Program in c++ 2. Array declaration and definition 3. Enter the element to be counted 4. Counter or freq variable declaration 5. Print the particular element along with a number how many times that number gets repeated in the given array
  • 3. Logic • Given array for example: • arr[]={1,2,3,2,3,2,2} • Element to be find is 2 (No.of times repeated) • How to find the repeated element present in an array • Soln:Using for loop: • for (i=0;i<n;i++) • if(a[i]==ele)(main logic) • counter++;
  • 4. Let’s See Practically by writing the program
  • 5. • #include<iostream.h> • #include<conio.h> • void main() • { • int a[100],ele,n,i,freq; • clrscr(); • cout<<"Enter the size of array"<<endl; • cin>>n; • cout<<"Enter the elements of array"<<endl; • for(i=0;i<n;i++) • { • cin>>a[i]; • } • cout<<"Enter the element to be counted"<<endl; • cin>>ele; • freq=0; • for(i=0;i<n;i++) • { • if(a[i]==ele) • { • freq=freq+1; • } • } • cout<<"Frequency of "<<ele<<" is "<<freq; • getch(); • }