← All resources

Write a function in C programming language that takes an array pointer and the size of the array as parameter and sorts it in ascending order.

#include<stdio.h>
#include<conio.h>
void bubble(int *p, int n)
{
	int i, j, tmp;
	printf("nInside Bubble Functionn");
	for(i=0;i<n;i++)
	{
		for(j=0;j<n-1-i;j++)
		{
			if(*(p+j)>*(p+j+1))
			{
				tmp = *(p+j);
				*(p+j) = *(p+j+1);
				*(p+j+1) = tmp;
			}
		}
	}
}
void main()
{
	int a[10], i;
	clrscr();
	printf("nEnter the values for the array:n");
	for(i=0;i<10;i++)
	{
		scanf("%d", &a[i]);
	}
	bubble(&a[0], 10);
	printf("nArray after passing:n");
	for(i=0;i<10;i++)
	{
		printf("%dn", a[i]);
	}
	getch();
}