write a program of bubble sort using pointer?

Answers were Sorted based on User's Feedback



write a program of bubble sort using pointer?..

Answer / 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

write a program of bubble sort using pointer?..

Answer / 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

write a program of bubble sort using pointer?..

Answer / 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

More C Interview Questions

How many keywords (reserve words) are in c?

0 Answers  


What is pointers in c with example?

0 Answers  


pgm to find middle element of linklist(in efficent manner)

4 Answers   Huawei,


given the piece of code int a[50]; int *pa; pa=a; to access the 6th element of the array which of the following is incorrect? a.*(a+5) b.a[5] c.pa[5] d.*(*pa + 5)

6 Answers   amu, TCS,


Explain what are reserved words?

0 Answers  






Why can't I perform arithmetic on a void* pointer?

0 Answers  


write a c program to print "Welcome" without using semicolon in the whole program ??

15 Answers   Infosys, TCS,


Write a program to identify if a given binary tree is balanced or not.

0 Answers   JPMorgan Chase,


Are c and c++ the same?

0 Answers  


What is pragma c?

0 Answers  


What are enums in c?

0 Answers  


a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler

0 Answers  


Categories