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
Can you please explain the difference between exit() and _exit() function?
What is the use of pragma in embedded c?
Do you know what are bitwise shift operators in c programming?
What is volatile variable in c with example?
Why clrscr is used after variable declaration?
Write a program to print “hello world” without using semicolon?
What is declaration and definition in c?
how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software
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
what are bit fields? What is the use of bit fields in a structure declaration?
What is a pointer in c?
What is the concatenation operator?
What does s c mean on snapchat?
What is a keyword?
What is the size of a union variable?