In C++ code. Given an array with 35 integers, print out only those numbers that occur more than once. The 35 integers must be read from a txt file (using fstream) or randomly generated (No user input).
C++ CODE:
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
//array to store the 35 integers
int arr[35];
int i,j;
//seed for random number
srand(time(0));
//generating 35 numbers from 1 to 100
for(i=0;i<35;i++)
{
arr[i]=rand() % 100 + 1;
}
//printing the repeated numbers in the array
cout<<"The repeated numbers in the array are:
"<<endl;
for(i = 0; i < 35; i++)
for(j = i + 1; j <
35; j++)
if(arr[i] ==
arr[j])
cout<<arr[i]<<endl ;
return 0;
}
SCREENSHOT FOR OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.