write a program of bubble sort using pointer?
Answer Posted / anuj pratap singh
#include<stdio.h>
#include<conio.h>
void sort(int *,int );//prototype
void main()
{
int a[5],size=5; //let suppose
int i;
clrscr();
printf("Enter the elements according to size:");
for(i=0;i<size;i++)
{
scanf("%d",&a[i]);
}
sort(a,size); //calling function
printf(\n\npress any key to exit);
getch();
}
void sort(int *p,int size) //called function
{
int i,j,temp;
for(i=0;i<size-1;i++)
{
for(j=0;j<size-i-1;j++)
{
if(*(p+J)>*(p+j+1))
{
temp=*(p+J);
*(p+J)=*(p+J+1);
*(p+J+1)=temp;
}
}
}
for(i=0;i<size;i++)
{ pritf("%d",*(p+i));
}
}
| Is This Answer Correct ? | 40 Yes | 14 No |
Post New Answer View All Answers
What is the difference between #include
Why do we use null pointer?
What is multidimensional arrays
What are global variables?
Why main is not a keyword in c?
What is New modifiers?
What is the difference between local variable and global variable in c?
What does %p mean c?
When a c file is executed there are many files that are automatically opened what are they files?
What are extern variables in c?
How can you check to see whether a symbol is defined?
How does selection sort work in c?
What is infinite loop?
Why doesnt this code work?
Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)