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...

array contains zeros and ones as elements.we need to bring
zeros one side and one other side in single parse.
ex:a[]={0,0,1,0,1,1,0,0}
o/p={0,0,0,0,0,1,1,1}

Answer Posted / satinder singh

I Hope this will also work for this question.
I just took it for length of 8 but we can extend it to any
level.

void swap(int* p, int x, int y)
{
int tmp;
tmp = *(p+x);
*(p+x) = *(p+y);
*(p+y) = tmp;
}
int main()
{
int* ptr = (int*)malloc(sizeof(8));
int c, i, j;

for(c=0; c<8 ; c++) scanf("%d", ptr+c);

for(i=0; i<8; i++)
{
for(j=0; j<8; j++)
{
if( *(ptr+j) > *(ptr+j+1) ) swap(ptr, j, j+1);
}
}

for(c=0;c<8;c++) printf("%d", *(ptr+c));
return 0;
}

Is This Answer Correct ?    2 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can an array be an Ivalue?

1104


Give basis knowledge of web designing ...

2023


When should a far pointer be used?

1141


Can a variable be both constant and volatile?

1134


Explain what are header files and explain what are its uses in c programming?

1162


Tell me when would you use a pointer to a function?

1075


Describe static function with its usage?

1219


Is a house a mass structure?

1103


What do you mean by dynamic memory allocation in c?

1110


Write a program to reverse a string.

1086


Why use int main instead of void main?

1127


How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?

1120


Explain b+ tree?

1079


Can you add pointers together? Why would you?

1134


Explain how can you determine the size of an allocated portion of memory?

1119