wap for bubble sort

Answers were Sorted based on User's Feedback



wap for bubble sort..

Answer / guru1985

#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],i,j,r,temp;
printf("Enter the Range:");
scanf("%d",&r);
for(i=0;i<r;i++)
{
printf("Enter the Eliment No. %d",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<r;i++)
{
temp=0;
for(j=i+1;j<r;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("After Sorting:");
for(i=0;i<r;i++)
{
printf("\n%d",a[i]);
}
}

Is This Answer Correct ?    15 Yes 4 No

wap for bubble sort..

Answer / mandeep m gaba

//n=No of elements in an array;
int n;
int []a;
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(a[j]>a[j+1])
{ //swap function for the variables in the array
int temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}

Is This Answer Correct ?    11 Yes 8 No

wap for bubble sort..

Answer / sachin

n=No of elements in an array;

for(i=0;i<n;i++)
{for(j=0;j<n-i;j++)
{if(arr[j]>arr[j+1])
swap(arr[j],arr[j+1]);
}
}

void swap(int*x, int*y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}

Is This Answer Correct ?    7 Yes 10 No

Post New Answer

More C C++ Errors Interview Questions

A sample program using data structure? what is file handling?

0 Answers   TCS,


How to create a program that lists countries capitals when country is entered? (Terribly sorry, I'm a complete novist to coding with C, am looking for inspiration and general tips on how to code and create this program.)

0 Answers  


void main() { int i=5,y=3,z=2,ans; clrscr(); printf("%d",++i + --z + i++ + --i * ++y); i=5,y=3,z=2; ans=++i + --z + i++ + --i * ++y; printf("\n%d",ans); getch(); } Its output is 37 and 31.... Please explain me why its different How it works.....

2 Answers  


void main() { for(int i=0;i<5;i++); printf("%d",i); } What is the output?..

32 Answers   College School Exams Tests, CTS, HCL, iGate, SmartData,


Using string functions write a program that will accept the name of the capital as input value and will display the corresponding country. ------------------------ Capitals Countries ------------------------ Capitals Countries Ottawa Canada Moscow Russia Rome Italy I can't not get it to run properly

1 Answers   AMA,






Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have already been declared, use a do...while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total . Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total . Use no variables other than n , k , and total .

3 Answers  


Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a do...while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j .

2 Answers  


WHAT WILL BE THE OUTPUT OF THE FOLLOWING QUESTION void main() { int x=4,y=3,z; z=x-- -y; printf("%d%d%d",x,y,z); }

25 Answers   HCL,


How to upgrade LOOP environment, I just mean, how can i make loop statement editable ? I just try some program using loop statement and checking it in multiple compilers. Every compiler showing different output, what's the wrong ? is it a compiler based problem, or loop based problem, tell me why ? and what will be the debugging process, for this kind of problem ?

1 Answers  


Display this kind of output on screen. 1 0 1 1 0 1 3. Display this kind of output on screen. 1 1 0 1 0 1 4. Display this kind of output on screen. 1 1 0 1 0 1 5.Display this kind of output on screen. 1 2 3 4 5 6 7 8 9 10

1 Answers  


What is probability to guarantee that the task a programmer is going to create will be created and be able to run on a particular system (RTOS/GPOS).

0 Answers  


How to develop a program using C language to convert 8-bit binary values to decimals. TQ

1 Answers   Amazon,


Categories