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
How do you define CONSTANT in C?
Is c weakly typed?
Explain how can I write functions that take a variable number of arguments?
What is infinite loop?
What is a scope resolution operator in c?
What is Dynamic memory allocation in C? Name the dynamic allocation functions.
Write a program to find factorial of a number using recursive function.
What is the difference between malloc() and calloc() function in c language?
What are the storage classes in C?
If fflush wont work, what can I use to flush input?
How do I get a null pointer in my programs?
Which is an example of a structural homology?
Give differences between - new and malloc() , delete and free() ?
Which header file is used for clrscr?
Are local variables initialized to zero by default in c?