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
Is javascript based on c?
Is null valid for pointers to functions?
What is hashing in c language?
What is the code for 3 questions and answer check in VisualBasic.Net?
What is pragma in c?
Why c is a procedural language?
How does free() know explain how much memory to release?
Can we declare a function inside a function in c?
find the sum of two matrices and WAP for it.
What is meant by realloc()?
Is there a way to switch on strings?
what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;
What are qualifiers?
Can a pointer point to null?
What is meant by inheritance?