Q:

Write a C++ program to find the two repeating elements in a given array of integers

0

Write a C++ program to find the two repeating elements in a given array of integers

Sample Output:

Original array: 1 2 3 5 5 7 8 8 9 9 2 
Repeating elements: 2 5 8 9

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;

int main()
{
    int nums[] = {1, 2, 3, 5, 5, 7, 8, 8, 9, 9, 2}; 
    int i, j;
    int size = sizeof(nums)/sizeof(nums[0]);
    cout << "Original array: ";
    for (i = 0; i < size; i++) 
    cout << nums[i] <<" ";
    cout  << "\nRepeating elements: ";
    for(i = 0; i < size; i++)
    for(j = i+1; j < size; j++)
      if(nums[i] == nums[j])
        cout <<  nums[i] << " ";
       
    return 0;
 
   }

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now