Bubble sort help plz
plz help,im getting incorrect output
#include
int main()
{
int i,pass,temp,a[10],n;
printf("Enter the number of elements you would like to enter");
printf("%d",n);
printf("Enter the elements of the array");
for(i=0;i
scanf("%d",&a);
for(pass=1;pass<=n-1;pass++)
{
for(i=0;i<=n-1-pass;i++)
{
if(a>a[i+1])
{
temp=a;
a=a[i+1];
a[i+1]=temp;
}
}
}
printf("The sorted array is");
printf("%d",a);
return 0;
}
#include
int main()
{
int i,pass,temp,a[10],n;
printf("Enter the number of elements you would like to enter");
printf("%d",n);
printf("Enter the elements of the array");
for(i=0;i
for(pass=1;pass<=n-1;pass++)
{
for(i=0;i<=n-1-pass;i++)
{
if(a>a[i+1])
{
temp=a;
a=a[i+1];
a[i+1]=temp;
}
}
}
printf("The sorted array is");
printf("%d",a);
return 0;
}
Replies
-
PraveenKumar PurushothamanTry this...
#include
#include void bubble(int a[],int n) { int i, j, t; for(i = n-2;i >= 0;i--) { for(j=0;j<=i;j++) { if(a[j]>a[j+1]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } } void main() { int a[100],n,i; clrscr(); printf("\n\n Enter integer value for total no.s of elements to be sorted: "); scanf("%d",&n); for( i=0;i<=n-1;i++) { printf("\n\n Enter integer value for element no.%d : ",i+1); scanf("%d",&a[i]); } bubble(a,n); printf("\n\n Finally sorted array is: "); for( i=0;i<=n-1;i++) printf("%3d",a[i]); } -
PraveenKumar PurushothamanSorry for double posting... 😔
-
Aman Goyalthanku Praveen but plz do find the bug in my code,i think my logic is right
-
PraveenKumar PurushothamanWhat output are you getting?
You are reading an archived discussion.
Related Posts
Guys, recently I came to know that TATA nano, the much hyped about so called cheapest car is being sold for 800,000 Nepalese Rupees in Nepal. It is roughly around...
I currently took admission in College of Engineering, Pune, Maharashtra, India for M.Tech Mechatronics.
I would like to know the opportunities of doing this branch.
Also if anyone could provide...
Hai Friends,
I've just joined the Crazy Engineers club. I'm a final year student doing B.E. -E.C.E. I am hoping to get ideas about projects related to Mass Alert Messaging...
unsectorized source code for 3G handover in mobile wireless network matlab www.pudn.com
This is matlab code of handover in 3G network
u can't download the file before register in the...
Am currently working on how to enhance the battery life span especially the one to be used in d design of an electric car.. Does anyone have ideal on what...