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
What are pointers in C? Give an example where to illustrate their significance.
Can a pointer point to null?
What is spark map function?
What are disadvantages of C language.
What is the difference between array and pointer?
What is operator precedence?
What is c basic?
How can you read a directory in a C program?
What is structure padding in c?
Write a program to reverse a string.
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
Is null valid for pointers to functions?
Is c is a procedural language?
provide an example of the Group by clause, when would you use this clause
what is the difference between 123 and 0123 in c?