64 665
Assignments Done
99,2%
Successfully Done
In September 2018

Answer to Question #31718 in C++ for MANMOHAN SHARMA

Question #31718
Write function for removing duplicate elements from a given array and sort that array. (Without using inbuilt functions). For Example: Array = {2, 1, 3, 2, 4, 4, 6, 5, 6} Output = {1, 2, 3, 4, 5, 6}
Expert's answer
#include <iostream>
using namespace std;

int main() {
cout << "Input array length: ";
int n;
cin >> n;
int a[100];
for (int i = 0; i < n; i++) {
& cout << "Input element " << i << ": ";
& cin >> a[i];
}
for (int i = 0; i < n; i++)
& for (int j = 0; j < n-1; j++)
if (a[j] > a[j+1]) swap(a[j], a[j+1]);
for (int i = 1; i < n; i++) {
& if (a[i] == a[i-1]) {
for (int j = i; j < n-1; j++)
a[j] = a[j+1];
--n;
--i;
& }
}

cout << "Resulting array: " << endl;
for (int i = 0; i < n; i++)
& cout << a[i] << " ";
cout << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions