Use an array. The program should read 25 integers from a user. Each value should be between 5- 100 (5<-value<-100). As the user inputs values store all the values which are not a duplicate. Print all the array values at the end. Use the smallest possible array.
Here is the C++ code to implement the above given task
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr[25];
int f = 25;
int a, b, d;
//Asking the user to eneter the values of the array
cout<<"Enter the values in array : ";
for(a=0; a<f; a++)
{
cin>>arr[a];
}
// Find the duplicate values in array
for(a=0; a<f; a++)
{
for(b=a+1; b<f; b++)
{
//checks for dupliacte values
if(arr[a] == arr[b])
{
for(d=b; d<f; d++)
{
arr[d] = arr[d + 1];
}
//remove the duplicate values and decerements them
f--;
b--; // do not increment b if the values are shifiting
}
}
}
// Printing array after deleting duplicate values
cout<<"\n The values of the array at the end : ";
for(a=0; a<f; a++)
{
cout<<" "<<arr[a];
}
return 0;
}
Note: Since i don't have C++ compiler in my PC, I am executing the code in online C++ complier
Step by step
Solved in 3 steps with 2 images