Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main(){
- int nums[10] = {2,7,2,5,4,0,7,6,9,0};
- int a, b, t;
- int size;
- size = 10; //array size
- //display sorted array
- cout << "Values in array: \n";
- for (t = 0; t < size; t++) cout << nums[t] << " ";
- cout << "\n\n";
- //this is the bubble sort
- for (a = 1; a < size; a++){
- for (b = size - 1; b >= a; b--){
- if (nums[b - 1] > nums[b]){
- t = nums[b - 1];
- nums[b - 1] = nums[b];
- nums[b] = t;
- }
- }
- }
- //check if element is duplicate
- for (int i = 0; i < size; i++){
- if (nums[i] == nums[i + 1]){
- cout << nums[i + 1] << " is a duplicate." << "\n";
- }
- }
- cout << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment