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

hat is a pointer?

4 Answers   Assurgent,


write a c programs to do multiplication of two numbers with out using arithmatic operator ??????????

7 Answers   Infosys, TCS,


What are c identifiers?

0 Answers  


Can we use visual studio for c?

0 Answers  


What is the use of bitwise operator?

0 Answers  






Is c weakly typed?

0 Answers  


shorting algorithmS

0 Answers   Wipro,


In C programming, what command or code can be used to determine if a number of odd or even?

0 Answers  


What is the difference between exit() and _exit() function?

0 Answers  


Is array a primitive data type in c?

0 Answers  


What is C language ?

0 Answers   Jekson,


What is int main () in c?

0 Answers  


Categories