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 wild pointer in c?
What library is sizeof in c?
How can you return multiple values from a function?
How was c created?
How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same
How do you determine whether to use a stream function or a low-level function?
Why is c used in embedded systems?
What are multibyte characters?
Why main function is special give two reasons?
What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?
Differentiate between a structure and a union.
pierrot's divisor program using c or c++ code
Process by which one bit pattern in to another by bit wise operation is?
What is 02d in c?
What is a structure and why it is used?