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
What is a scope resolution operator in c?
What will be your course of action for a push operation?
Write a code to generate a series where the next element is the sum of last k terms.
Is anything faster than c?
How can you be sure that a program follows the ANSI C standard?
What is the most efficient way to store flag values?
What is the use of function in c?
What is keyword with example?
What are the rules for the identifier?
#include main() { char s[] = "Bouquets and Brickbats"; printf(" %c, ",*(&s[2])); printf("%s, ",s+5); printf(" %s",s); printf(" %c",*(s+2)); }
What do you mean by a local block?
Why does not c have an exponentiation operator?
code for replace tabs with equivalent number of blanks
int i=10; printf("%d %d %d", i, i=20, i);
Can a program have two main functions?