Skip to main content

PROGAM TO SORT ARRAY AT USER DEFINED POSITION

 #include<iostream>

using namespace std;

int main()

{

  int size,i,j,position,temp;

  cout<<"Enter the size of array:-\t";

  cin>>size;

  int array[size];

  for(i=0;i<size;i++)

    cin>>array[i];

  cout<<"Enter the index number from where you want to sort array in ascending order:-\n";

  cin>>position;

  for(i=position-1;i<size;i++)

    for(j=position;j<size;j++)

      if(array[i]<array[j])

      {

        temp=array[i];

        array[i]=array[j];

        array[j]=temp;

      }

  cout<<"New sorted array is :-\n";

  for(i=0;i<size;i++)

    cout<<array[i]<<" ";

}

Comments

Popular posts from this blog

example of typecasting in c

/*Type Casting in C Typecasting allows us to convert one data type into other. */ //simple example to cast int value into the float. #include <stdio.h>    int   main (){   float   f = ( float ) 9 / 4 ;     printf ( "f : %f \n " ,  f  );     return   0 ;   }