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

‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.

1872


Write a program of prime number using recursion.

613


What does %d do in c?

537


write a progrmm in c language take user interface generate table using for loop?

1571


How to get string length of given string in c?

601






Is null valid for pointers to functions?

603


What are runtime error?

623


How to write c functions that modify head pointer of a linked list?

539


Tell us two differences between new () and malloc ()?

608


How can I delete a file?

626


Write a program on swapping (100, 50)

634


What is the use of define in c?

590


Compare and contrast compilers from interpreters.

679


What is an arrays?

648


What is non linear data structure in c?

567