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 calloc malloc realloc in c?
#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }
Write an efficient algo and C code to shuffle a pack of cards.. this one was a feedback process until we came up with one with no extra storage.
What is %lu in c?
Explain how can I make sure that my program is the only one accessing a file?
Device an algorithm for weiler-atherton polygon clipping, where the clipping window can be any specified polygon
What are the types of operators in c?
What is the significance of an algorithm to C programming?
Why can't I perform arithmetic on a void* pointer?
What is difference between scanf and gets?
What are the usage of pointer in c?
What are the three constants used in c?
Do pointers store the address of value or the actual value of a variable?
Can you explain what keyboard debouncing is, and where and why we us it? please give some examples
What are structure types in C?