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

Is c easy to learn?

562


1.int a=10; 2.int b=20; 3. //write here 4.b=30; Write code at line 3 so that when the value of b is changed variable a should automatically change with same value as b. 5.

1664


Explain the difference between malloc() and calloc() in c?

580


What's the right way to use errno?

626


Why is structure padding done in c?

650






What is the use of putchar function?

652


Do pointers store the address of value or the actual value of a variable?

612


What are the salient features of c languages?

626


What is structure in c language?

620


Is swift based on c?

641


please explain every phase in the "SDLC" in the dotnet.

2180


What is the use of bit field?

644


What does void main return?

607


What is getch c?

858


Explain what is the difference between null and nul?

660