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
Explain a file operation in C with an example.
State the difference between x3 and x[3].
What are the rules for the identifier?
What is pass by reference in functions?
Why do we use null pointer?
What is operator promotion?
Explain the difference between ++u and u++?
code for find determinent of amatrix
What is an auto keyword in c?
Which function in C can be used to append a string to another string?
Explain what does the format %10.2 mean when included in a printf statement?
What is array of structure in c?
What are keywords c?
What is meant by high-order and low-order bytes?
What is dynamic variable in c?