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
Multiply an Integer Number by 2 Without Using Multiplication Operator
What is file in c preprocessor?
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
What is a structure and why it is used?
How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?
What is data structure in c programming?
Why do we use header files in c?
Write a program for Overriding.
Is null always defined as 0(zero)?
Why static is used in c?
Explain 'far' and 'near' pointers in c.
What is sizeof in c?
What is the 'named constructor idiom'?
Why c is a procedural language?
in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.