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 / rizwan

This program will work perfectly. I hope this is the exact
answer to the question.

#include<stdio.h>

void swap(int *a, int *b)
{
int temp;
temp = *b;
*b=*a;
*a=temp;
}

int main()
{
int a[]={0,0,1,0,1,1,0,0};
int i,j;

for(i=0;i<8;i++)
{
if(a[i])
{
j=i+1;
while(j<8)
{
j++;
if(!a[j])
{
swap(&a[i],&a[j]);
break;
}
}

}
}

for(i=0;i<8;i++)
printf("%d ",a[i]);

return;
}

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain a file operation in C with an example.

1058


State the difference between x3 and x[3].

1053


What are the rules for the identifier?

1117


What is pass by reference in functions?

776


Why do we use null pointer?

999


What is operator promotion?

1013


Explain the difference between ++u and u++?

1071


code for find determinent of amatrix

1920


What is an auto keyword in c?

1048


Which function in C can be used to append a string to another string?

1181


Explain what does the format %10.2 mean when included in a printf statement?

1294


What is array of structure in c?

1101


What are keywords c?

985


What is meant by high-order and low-order bytes?

1005


What is dynamic variable in c?

990