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
How can I avoid the abort, retry, fail messages?
What is the meaning of 2d in c?
How will you write a code for accessing the length of an array without assigning it to another variable?
What is struct node in c?
Write a program to swap two numbers without using a temporary variable?
Why void main is used in c?
For what purpose null pointer used?
What is an lvalue?
Differentiate between ordinary variable and pointer in c.
What is variable initialization and why is it important?
What are the advantages and disadvantages of pointers?
What are linked lists in c?
What is double pointer?
What is the difference between pure virtual function and virtual function?
write a C program:There is a mobile keypad with numbers 0-9 and alphabets on it. Take input 0f 7 keys and then form a word from the alphabets present on the keys.