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 / satinder singh
I Hope this will also work for this question.
I just took it for length of 8 but we can extend it to any
level.
void swap(int* p, int x, int y)
{
int tmp;
tmp = *(p+x);
*(p+x) = *(p+y);
*(p+y) = tmp;
}
int main()
{
int* ptr = (int*)malloc(sizeof(8));
int c, i, j;
for(c=0; c<8 ; c++) scanf("%d", ptr+c);
for(i=0; i<8; i++)
{
for(j=0; j<8; j++)
{
if( *(ptr+j) > *(ptr+j+1) ) swap(ptr, j, j+1);
}
}
for(c=0;c<8;c++) printf("%d", *(ptr+c));
return 0;
}
| Is This Answer Correct ? | 2 Yes | 8 No |
Post New Answer View All Answers
Describe explain how arrays can be passed to a user defined function
What is #include cctype?
Can we declare a function inside a function in c?
What is a pointer and how it is initialized?
Write a code to generate divisors of an integer?
Is the exit() function same as the return statement? Explain.
What is extern c used for?
Explain what are preprocessor directives?
Is that possible to store 32768 in an int data type variable?
what is the diffrenet bettwen HTTP and internet protocol
plz let me know how to become a telecom protocol tester. thank you.
Explain the use of 'auto' keyword
Explain the priority queues?
When the macros gets expanded?
What is volatile, register definition in C