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

What is the out put of this programme? int a,b,c,d; printf("Enter Number!\n"); scanf("%d",&a); while(a=!0) { printf("Enter numbers/n"); scanf("%d%d%d",&b,&c,&d); a=a*b*c*d; } printf("thanks!"); getche(); Entering numbers are a=1,b=2,c=3,d=4 b=3,c=4,d=-5 b=3,c=4,d=0

5 Answers   TCS,


class test { int a; public: test(int b):a(b){} void show(){ cout<<a; } }; void main() { test t1; test t2(5); t1.show(); t2.show(); } }

1 Answers  


char* f() return "hello:"; void main() {char *str=f(); }

1 Answers  


I'm having trouble with coming up with the correct code. Do I need to put a loop? Please let me know if I'm on the right track and what areas I need to correct. I still don't have a good grasp on this programming stuff. Thanks =) The assignment was to write a program using string functions that accepts a coded value of an item and displays its equivalent tag price. The base of the keys: 0 1 2 3 4 5 6 7 8 9 X C O M P U T E R S Sample I/O Dialogue: Enter coded value: TR.XX Tag Price : 68.00

3 Answers   UCB,


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,






I'm having trouble with coming up with the correct code. Thank You!! The assignment was to write a program using string functions that accepts a price of an item and displays its coded value. The base of the keys: X C O M P U T E R S 0 1 2 3 4 5 6 7 8 9 Sample I/O Dialogue: Enter Price: 489.50 Coded Value: PRS.UX

0 Answers  


when i use cout or cin call & then either << or >> .....it shows declaration syntax error...what should i do? cout<<"anything"; int a; cin>>a; return 0;

2 Answers  


Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all the non-negative values into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0. Instructor's notes: This problem requires either a while or a do-while loop.

3 Answers  


how tally is useful?

2 Answers  


what is meant for variable not found?

3 Answers  


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

1 Answers   Amazon,


loop1: { x=i<n?(i++):0; printf("%d",i); exit(x); continue; } Error- misplaced continue. Doubt-1.will the exit(x) be executed for all values of x 2.will this statement go out of the program.

5 Answers   CMC,


Categories