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

Which is best linux os?

556


What is the function of multilevel pointer in c?

665


Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.

4835


What is NULL pointer?

671


why wipro wase

1823






Explain what is a const pointer?

634


What is pragma in c?

623


difference between Low, Middle, High Level languages in c ?

1628


What is sizeof int in c?

594


what is the c source code for the below output? 10 10 10 10 10 10 10 10 10 10 9 9 7 6 6 6 6 6 6 9 7 5 9 7 3 2 2 5 9 7 3 1 5 9 7 3 5 9 7 4 4 4 4 5 9 7 8 8 8 8 8 8 8 8 9

1426


Does free set pointer to null?

551


Are negative numbers true in c?

595


What is the difference between text and binary i/o?

586


What is the use of f in c?

551


Explain how can you restore a redirected standard stream?

585