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
What is switch in c?
What is quick sort in c?
Why cant I open a file by its explicit path?
Explain what is page thrashing?
hi, which software companys will take,if d candidate's % is jst 55%?
What is difference between stdio h and conio h?
Combinations of fibanocci prime series
how can I convert a string to a number?
How can I find the modification date and time of a file?
What is hashing in c?
Can we change the value of static variable in c?
int i[2], j; int *pi;i[0] = 1; i[1] = 5; pi = i; j = *pi + 1 + *(pi + 1)Value of j after execution of the above statements will be a) 7 b) 6 c) 4 d) pointer
Can math operations be performed on a void pointer?
Why do we use c for the speed of light?
What is the size of structure pointer in c?