title: My Bubble Sort Program worked for one case but not for other. How this is Possible?
body: <pre><code>#include&lt;iostream&gt;
  using namespace std;
  int main(){
      int n;
      cout&lt;&lt;&quot;Enter size of array-&quot;;
      cin&gt;&gt;n;
      int arr[n];
      cout&lt;&lt;&quot;Enter all elements&quot;&lt;&lt;endl;
      for(int i=0;i&lt;n;i++){
          cin&gt;&gt;arr[i];
      }
      cout&lt;&lt;&quot;Your Entered elements are&quot;&lt;&lt;endl;
      for(int i=0;i&lt;n;i++){
          cout&lt;&lt;arr[i]&lt;&lt;&quot;,&quot;;
      }
      cout&lt;&lt;endl;
      for(int x=0;0&lt;n-x;x++){
          for(int i=0;i&lt;n;i++){
              if(arr[i]&gt;arr[i+1]){
                  int tem=arr[i];
                  arr[i]=arr[i+1];
                  arr[i+1]=tem;
              }
          }
      }
      cout&lt;&lt;&quot;Sorted Array&quot;&lt;&lt;endl;
      for(int i=0;i&lt;n;i++){
          cout&lt;&lt;arr[i]&lt;&lt;&quot;,&quot;;
      }
      return 0;
  }
  </code></pre>
  <blockquote>
  <p>For first case
  Enter size of array-6
  Enter all elements
  4 5 3 2 1 9
  Your Entered elements are
  4,5,3,2,1,9,
  Sorted Array
  1,2,3,4,5,9,
  For second case(This have Problem)
  Enter size of array-4
  Enter all elements
  20
  40
  30
  50
  Your Entered elements are
  20,40,30,50,</p>
  </blockquote>