how to write a bubble sort program without using temporary
variable?



how to write a bubble sort program without using temporary variable?..

Answer / nitin garg

#include <stdio.h>
#include <conio.h>
#include <string.h>


int main()
{

int num[100],n,i,j;
printf("how many elements you enter
");
scanf("%d",&n);
printf("Enter %d elements
",n);
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
}

for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(num[j]>num[i])
{
num[i]=num[i]+num[j];
num[j]=num[i]-num[j];
num[i]=num[i]-num[j];

}
}
}
printf("

Sorted in Ascending order
");
for(i=0;i<n;i++)
{
printf("%d
",num[i]);
}

getch();
}

Is This Answer Correct ?    15 Yes 4 No

Post New Answer

More C Interview Questions

application of static variables in real time

1 Answers   Bosch,


What is wrong with this statement? Myname = 'robin';

0 Answers  


what is inline function?

2 Answers  


how to make program without <> in libray.

0 Answers  


How can I read a directory in a C program?

2 Answers   Bright Outdoor, Wipro,






Where are the auto variables stored?

0 Answers   TISL,


What does the message "automatic aggregate intialization is an ansi feature" mean?

0 Answers  


what will be the output off the following program? #include<stdio.h> int main() { int a; a=015+0*71+5; printf("%d,a"); return0; }

9 Answers   HCL,


could u able to tell about suresoft technical session

1 Answers  


How is null defined in c?

0 Answers  


Write a program to replace n bits from the position p of the bit representation of an inputted character x with the one's complement. Method invertBit takes 3 parameters x as input character, p as position and n as the number of positions from p. Replace n bits from pth position in 8 bit character x. Then return the characters by inverting the bits.

0 Answers   Infosys,


what is the differnce between AF_INET and PF_INET?

5 Answers   Systems Plus, Wipro,


Categories