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

Is javascript based on c?

591


Is null valid for pointers to functions?

605


What is hashing in c language?

611


What is the code for 3 questions and answer check in VisualBasic.Net?

1682


What is pragma in c?

623






Why c is a procedural language?

578


How does free() know explain how much memory to release?

615


Can we declare a function inside a function in c?

579


find the sum of two matrices and WAP for it.

627


What is meant by realloc()?

668


Is there a way to switch on strings?

610


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

1879


What are qualifiers?

613


Can a pointer point to null?

582


What is meant by inheritance?

627