write a program of bubble sort using pointer?

Answer Posted / nitish-csedu

#include<stdio.h>
int main()
{
int n,i,j,temp,a[1000],*p;
scanf("%d",&n);
p=&a[0];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(*(p+i)>(*(p+j)))
{
temp=*(p+i);
*(p+i)=*(p+j);
*(p+j)=temp;
}
}
}
for(i=0;i<n;i++)
{
printf("%d ",*(p+i));
}
return 0;
}

Is This Answer Correct ?    10 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can you please explain the difference between exit() and _exit() function?

606


What is the use of pragma in embedded c?

597


Do you know what are bitwise shift operators in c programming?

599


What is volatile variable in c with example?

596


Why clrscr is used after variable declaration?

1053






Write a program to print “hello world” without using semicolon?

683


What is declaration and definition in c?

537


how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software

2816


write a program which the o/p should b in such a way that s triangle if I/p is 3,a Square/rectangle if I/P=4,a pentagon if I/P=5 and so on...forget about the I/P which is less than 3

1650


what are bit fields? What is the use of bit fields in a structure declaration?

1510


What is a pointer in c?

696


What is the concatenation operator?

620


What does s c mean on snapchat?

592


What is a keyword?

757


What is the size of a union variable?

608