write a program of bubble sort using pointer?

Answer Posted / anuj pratap singh

#include<stdio.h>
#include<conio.h>
void sort(int *,int );//prototype
void main()
{
int a[5],size=5; //let suppose
int i;
clrscr();
printf("Enter the elements according to size:");
for(i=0;i<size;i++)
{
scanf("%d",&a[i]);
}
sort(a,size); //calling function
printf(\n\npress any key to exit);
getch();
}
void sort(int *p,int size) //called function
{
int i,j,temp;
for(i=0;i<size-1;i++)
{
for(j=0;j<size-i-1;j++)
{
if(*(p+J)>*(p+j+1))
{
temp=*(p+J);
*(p+J)=*(p+J+1);
*(p+J+1)=temp;
}
}
}

for(i=0;i<size;i++)
{ pritf("%d",*(p+i));
}
}

Is This Answer Correct ?    40 Yes 14 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I avoid the abort, retry, fail messages?

665


What is the meaning of 2d in c?

617


How will you write a code for accessing the length of an array without assigning it to another variable?

619


What is struct node in c?

624


Write a program to swap two numbers without using a temporary variable?

613






Why void main is used in c?

564


For what purpose null pointer used?

610


What is an lvalue?

638


Differentiate between ordinary variable and pointer in c.

625


What is variable initialization and why is it important?

623


What are the advantages and disadvantages of pointers?

584


What are linked lists in c?

652


What is double pointer?

563


What is the difference between pure virtual function and virtual function?

656


write a C program:There is a mobile keypad with numbers 0-9 and alphabets on it. Take input 0f 7 keys and then form a word from the alphabets present on the keys.

14972