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 / manoj
#include<stdio.h>
#include<conio.h>
void main()
{
int a[]={0,0,1,0,1,1,0,0};
int *arrayTemp = a;
int i, j_0 = 0, j_8 = 8;
for(int data = 0; *a != '\0'; *a++)
{
data = *a;
if(data == 1 )
{
a[j_0++] = data;
}
else
{
a[j_8--] = data;
} // if-else block
}//for loop
}//main function
for(i=0; i< 8; i ++)
{
printf("array value is %d", a[i]);
}
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
Why can arithmetic operations not be performed on void pointers?
write a program to print data of 5 five students with structures?
Are pointers integer?
why we wont use '&' sing in aceesing the string using scanf
Can a file other than a .h file be included with #include?
How are 16- and 32-bit numbers stored?
what is the significance of static storage class specifier?
What is queue in c?
Explain what does the function toupper() do?
please send me the code for multiplying sparse matrix using c
What is the advantage of a random access file?
What is difference between static and global variable in c?
Write a C program in Fibonacci series.
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
how to write optimum code to divide a 50 digit number with a 25 digit number??