Welcome

Hi! This blog is for beginners of c++ and java .You can check and pick codes for your programming assignments. This will also help you to understand the concepts of these programming languages. Its all about programming.

Array in Ascending & Descending order

Tuesday, June 7, 2011

#include <iostream.h>

int main()
{

  int array[10];
  int temp;

  for(int x=0;x<10;x++)
  {
  cout << "Enter Integer No. " << x+1 << " : " ;
  cin>>array[x];
  }

  for (x=0;x<10;x++)
  {
      for(int y=0;y<9;y++)
      {
          if(array[y]>array[y+1])
          {
          temp=array[y];
          array[y]=array[y+1];
          array[y+1]=temp;
          }
      }
  }


  cout << "Array in Ascending order is : ";

  for (x=0;x<10;x++)
  {
  cout << endl << array[x];
  }


  for (x=0;x<10;x++)
  {
      for(int y=0;y<9;y++)
      {
          if(array[y]<array[y+1])
          {
          temp=array[y];
          array[y]=array[y+1];
          array[y+1]=temp;
          }
      }
  }

  cout << endl;
  cout << "Array in Descending order is : ";

  for (x=0;x<10;x++)
  {
  cout << endl << array[x];
  }

return 0;
}