Program to reorder, rearrange list of numbers given by user


#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
main()
{
      int i,n,*x;
      void reorder(int n, int *x);
      printf("\nNumber of elements :");
      scanf("%d",&n);
      x=(int *)malloc(n*sizeof(int));
      for(i=0;i<n;i++)
      {
         printf("\nEnter integer :");
         scanf("%d",x+i);
      }
      reorder(n,x);
      system("cls");
      printf("\nReordered list \n");
      for(i=0;i<n;++i)
      {
          printf("%d\t",*(x+i));
      }
      getch();
      }
void reorder(int n, int *x)
{
     int i,j,temp;
     for(i=0;i<n-1;i++)
     for(j=i+1;j<n;j++)
     if(*(x+i)>*(x+j))
     {
         temp=*(x+i);
         *(x+i)=*(x+j);
         *(x+j)=temp;
     }
}

Comments

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples