write a program of bubble sort using pointer?

Answer Posted / gulam md gouss khan

#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\n press 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 ?    19 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Do character constants represent numerical values?

848


What is a buffer in c?

579


What is an lvalue in c?

698


What is difference between %d and %i in c?

698


What are inbuilt functions in c?

562






Is anything faster than c?

591


What is the difference between arrays and pointers?

638


What does the && operator do in a program code?

701


write an interactive C program that will encode or decode a line of text.To encode a line of text,proceed as follows. 1.convert each character,including blank spaces,to its ASCII equivalent. 2.Generate a positive random integer.add this integer to the ASCII equivalent of each character.The same random integer will be used for the entire line of text. 3.Suppose that N1 represents the lowest permissible value in the ASCII code,and N2 represents the highest permissible value.If the number obtained in step 2 above(i.e.,the original ASCII equivalent plus the random integer)exceeds N2,then subtract the largest possible multiple of N2 from this number,and add the remainder to N1.Hence the encoded number will always fall between N1 and N2,and will therefore always represent some ASCII character. 4.Dislay the characters that correspond to the encoded ASCII values.  The procedure is reversed when decoding a line of text.Be certain,however,that the same random number is used in decodingas was used in encoding.

2725


Write a program to print "hello world" without using a semicolon?

600


What is the use of function overloading in C?

686


How arrays can be passed to a user defined function

581


Why isnt there a numbered, multi-level break statement to break out

593


How can you increase the allowable number of simultaneously open files?

599


Give the rules for variable declaration?

682