Write a 'C' Program to accept 10 numbers from user,store these numbers in an array and sort an array elements in ascending order by using dynamic memory allocation.


#include

void main()
{
    int *ptr,i,j,temp;
    clrscr();
    ptr = (int *)malloc(sizeof(int) * 10);
    printf("\nENTER THE ELEMENT::>\n");
    for(i = 0 ; i < 10 ; i++)
    {
        scanf("%d",&ptr[i]);
    }
    for(i = 0 ; i < 10 ; i++)
    {
        for( j = i + 1 ;j < 10 ; j++)
        {
            if(ptr[i] > ptr[j])
            {
                temp   = ptr[i];
                ptr[i] = ptr[j];
                ptr[j] = temp;
            }
        }
    }
    printf("ELEMENTS IN ASCENDING ORDER ::>\n");
    for(i = 0 ; i < 10 ; i++)
    {
        printf("%d ",ptr[i]);
    }
    getch();
}
/*OUTPUT::

ENTER THE ELEMENT::>
6 1 2 4 8 10 23 2 5 7
ELEMENTS IN ASCENDING ORDER ::>
1 2 2 4 5 6 7 8 10 23

ENTER THE ELEMENT::>
10 65 23 45 78 65 32 64 25 78
ELEMENTS IN ASCENDING ORDER ::>
10 23 25 32 45 64 65 65 78 78
*/
Write a 'C' Program to accept 10 numbers from user,store these numbers in an array and sort an array elements in ascending order by using dynamic memory allocation. Write a 'C' Program to accept 10 numbers from user,store these numbers in an array and sort an array elements  in ascending order by using dynamic memory allocation. Reviewed by on April 24, 2015 Rating: 5
Powered by Blogger.