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
Is c easy to learn?
1.int a=10; 2.int b=20; 3. //write here 4.b=30; Write code at line 3 so that when the value of b is changed variable a should automatically change with same value as b. 5.
Explain the difference between malloc() and calloc() in c?
What's the right way to use errno?
Why is structure padding done in c?
What is the use of putchar function?
Do pointers store the address of value or the actual value of a variable?
What are the salient features of c languages?
What is structure in c language?
Is swift based on c?
please explain every phase in the "SDLC" in the dotnet.
What is the use of bit field?
What does void main return?
What is getch c?
Explain what is the difference between null and nul?