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

What are pointers in C? Give an example where to illustrate their significance.

1218


Can a pointer point to null?

1051


What is spark map function?

1112


What are disadvantages of C language.

1149


What is the difference between array and pointer?

994


What is operator precedence?

1188


What is c basic?

1158


How can you read a directory in a C program?

1129


What is structure padding in c?

1115


Write a program to reverse a string.

1063


the real constant in c can be expressed in which of the following forms a) fractional form only b) exponential form only c) ascii form only d) both a and b

2661


Is null valid for pointers to functions?

1157


Is c is a procedural language?

1073


provide an example of the Group by clause, when would you use this clause

2178


what is the difference between 123 and 0123 in c?

1191