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 can you tell whether two strings are the same?
Difference between goto, long jmp() and setjmp()?
What is an endless loop?
What is the difference between array and pointer in c?
How arrays can be passed to a user defined function
Why static variable is used in c?
I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...
a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler
How can I find the modification date of a file?
What are the 4 types of programming language?
What does the error 'Null Pointer Assignment' mean and what causes this error?
What are the disadvantages of external storage class?
Not all reserved words are written in lowercase. TRUE or FALSE?
List some of the static data structures in C?
What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?