- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C/C++ Program for Finding the Number Occurring Odd Number of Times?
A C++ program to find a number which occurs odd number of times in a given array of positive integers. In this array, all numbers occur even number of times.
Input: arr[] = {5, 7, 8, 8, 5, 8, 8, 7, 7} Output: 7
Explanation
Use two loops in which the outer loop traversed all elements one by one and inner loop counts the number of occurrences of the element traversed by the outer loop.
Example
#include <iostream> using namespace std; int Odd(int arr[], int n){ for (int i = 0; i < n; i++) { int ctr = 0; for (int j = 0; j < n; j++) { if (arr[i] == arr[j]) ctr++; } if (ctr % 2 != 0) return arr[i]; } return -1; } int main() { int arr[] = {5, 7, 8, 8, 5, 8, 8, 7, 7}; int n = 9; cout <<Odd(arr, n); return 0; }
- Related Articles
- C/C++ Program to Find the Number Occurring Odd Number of Times?
- Java Program to Find the Number Occurring Odd Number of Times
- Finding number that appears for odd times - JavaScript
- Python Program to Find Element Occurring Odd Number of Times in a List
- Find the Number Occurring Odd Number of Times using Lambda expression and reduce function in Python
- C Program for n-th odd number
- C Program for Find sum of odd factors of a number?
- C++ program for Find sum of odd factors of a number
- C++ Program to calculate the number of odd days in given number of years
- C/C++ Program for the Triangular Matchstick Number?
- Finding number of occurrences of the element appearing most number of times in JavaScript
- Number of integers with odd number of set bits in C++
- C/C++ Program for Triangular Matchstick Number?
- C/C++ Program for nth Catalan Number?
- C++ Program to Check Whether Number is Even or Odd

Advertisements