Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

How do you define CONSTANT in C?

1212


Is c weakly typed?

968


Explain how can I write functions that take a variable number of arguments?

1028


What is infinite loop?

1028


What is a scope resolution operator in c?

1205


What is Dynamic memory allocation in C? Name the dynamic allocation functions.

1334


Write a program to find factorial of a number using recursive function.

1065


What is the difference between malloc() and calloc() function in c language?

1029


What are the storage classes in C?

1069


If fflush wont work, what can I use to flush input?

1051


How do I get a null pointer in my programs?

1060


Which is an example of a structural homology?

1246


Give differences between - new and malloc() , delete and free() ?

1045


Which header file is used for clrscr?

999


Are local variables initialized to zero by default in c?

984