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

Multiply an Integer Number by 2 Without Using Multiplication Operator

326


What is file in c preprocessor?

658


Hai,I have done with my bachelor of commerce and planing to ms,please suggest me how to convince vo for shifting from commerce to computers. Visa on 8 DEC 2014  Npu university

1605


What is a structure and why it is used?

623


How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?

589






What is data structure in c programming?

579


Why do we use header files in c?

588


Write a program for Overriding.

693


Is null always defined as 0(zero)?

619


Why static is used in c?

627


Explain 'far' and 'near' pointers in c.

712


What is sizeof in c?

576


What is the 'named constructor idiom'?

645


Why c is a procedural language?

588


in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.

7414