Guest User

Untitled

a guest
Jul 4th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5.     int nums[10] = {2,7,2,5,4,0,7,6,9,0};
  6.     int a, b, t;
  7.     int size;
  8.  
  9.     size = 10; //array size
  10.  
  11.     //display sorted array
  12.     cout << "Values in array: \n";
  13.     for (t = 0; t < size; t++) cout << nums[t] << " ";
  14.     cout << "\n\n";
  15.  
  16.     //this is the bubble sort
  17.     for (a = 1; a < size; a++){
  18.         for (b = size - 1; b >= a; b--){
  19.             if (nums[b - 1] > nums[b]){
  20.                 t = nums[b - 1];
  21.                 nums[b - 1] = nums[b];
  22.                 nums[b] = t;
  23.             }
  24.         }
  25.     }
  26.  
  27.     //check if element is duplicate
  28.     for (int i = 0; i < size; i++){
  29.         if (nums[i] == nums[i + 1]){
  30.             cout << nums[i + 1] << " is a duplicate." << "\n";
  31.         }
  32.     }
  33.     cout << "\n";
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment