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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

How can you tell whether two strings are the same?

840


Difference between goto, long jmp() and setjmp()?

715


What is an endless loop?

816


What is the difference between array and pointer in c?

593


How arrays can be passed to a user defined function

585






Why static variable is used in c?

570


I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...

9665


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

628


How can I find the modification date of a file?

713


What are the 4 types of programming language?

599


What does the error 'Null Pointer Assignment' mean and what causes this error?

750


What are the disadvantages of external storage class?

600


Not all reserved words are written in lowercase. TRUE or FALSE?

733


List some of the static data structures in C?

768


What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?

598