Blame tests/upstream-test-suite/snippet_test.cpp

Than Ngo b7bcaa
#include <stdio.h>
Than Ngo b7bcaa
#include <stdlib.h>
Than Ngo b7bcaa
Than Ngo b7bcaa
void main()
Than Ngo b7bcaa
{
Than Ngo b7bcaa
  int i,n,temp,j,arr[25];
Than Ngo b7bcaa
  printf("Enter the number of elements in the Array: ");
Than Ngo b7bcaa
  scanf("%d",&n);
Than Ngo b7bcaa
  printf("\nEnter the elements:\n\n");
Than Ngo b7bcaa
Than Ngo b7bcaa
  /* [input] */
Than Ngo b7bcaa
  for(i=0 ; i
Than Ngo b7bcaa
  {
Than Ngo b7bcaa
    printf(" Array[%d] = ",i);
Than Ngo b7bcaa
    scanf("%d",&arr[i]);
Than Ngo b7bcaa
  }
Than Ngo b7bcaa
  /* [input] */
Than Ngo b7bcaa
Than Ngo b7bcaa
  // [bubble]
Than Ngo b7bcaa
  for(i=0 ; i
Than Ngo b7bcaa
  {
Than Ngo b7bcaa
    for(j=0 ; j
Than Ngo b7bcaa
    {
Than Ngo b7bcaa
      if(arr[j]>arr[j+1]) //Swapping Condition is Checked
Than Ngo b7bcaa
      {
Than Ngo b7bcaa
        temp=arr[j];
Than Ngo b7bcaa
        arr[j]=arr[j+1];
Than Ngo b7bcaa
        arr[j+1]=temp;
Than Ngo b7bcaa
      }
Than Ngo b7bcaa
    }
Than Ngo b7bcaa
  }
Than Ngo b7bcaa
  // [bubble]
Than Ngo b7bcaa
Than Ngo b7bcaa
  printf("\nThe Sorted Array is:\n\n");
Than Ngo b7bcaa
  /* [output] */
Than Ngo b7bcaa
  for(i=0 ; i
Than Ngo b7bcaa
  {
Than Ngo b7bcaa
    printf(" %4d",arr[i]);
Than Ngo b7bcaa
  }
Than Ngo b7bcaa
  /* [output] */
Than Ngo b7bcaa
}