how to write a bubble sort program without using temporary
variable?
Answer / 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 |
How do you construct an increment statement or decrement statement in C?
fn f(x) { if(x<=0) return; else f(x-1)+x; }
which do you prefer C or Pascal?
What is structure of c program?
How can I make a program in c to print 'Hello' without using semicolon in the code?
9 Answers C DAC, Practical Viva Questions,
write a programming in c to find the sum of all elements in an array through function.
why we are using semicolon at the end of printh statment
what is the output for this question: main() { int i=1; printf("%d%d%d",i,i++,++i); }
What is fflush() function?
What is the correct code to have following output in c using nested for loop?
write a c/c++ program that takes a 5 digit number and calculates 2 power that number and prints it?
If the size of int data type is two bytes, what is the range of signed int data type?