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

How do you construct an increment statement or decrement statement in C?

0 Answers  


fn f(x) { if(x<=0) return; else f(x-1)+x; }

5 Answers   HCL,


which do you prefer C or Pascal?

1 Answers  


What is structure of c program?

0 Answers  


How can I make a program in c to print 'Hello' without using semicolon in the code?

9 Answers   C DAC, Practical Viva Questions,






write a programming in c to find the sum of all elements in an array through function.

0 Answers  


why we are using semicolon at the end of printh statment

2 Answers   HCL,


what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }

9 Answers  


What is fflush() function?

0 Answers  


What is the correct code to have following output in c using nested for loop?

0 Answers  


write a c/c++ program that takes a 5 digit number and calculates 2 power that number and prints it?

4 Answers  


If the size of int data type is two bytes, what is the range of signed int data type?

0 Answers  


Categories