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 / vignesh1988i
#include<stdio.h>
#include<conio.h>
void main()
{
int *pointer,*pointer2,n;
printf("enter the no. of elements:");
scanf("%d",&n);
pointer=(int*)malloc(n*sizeof(n));
pointer2=(int*)malloc(n*sizeof(n));
for(int k=0,i=0,j=n-1;k<n;k++)
{
scanf("%d",(pointer+k));
if(*(pointer+k))
{
*(pointer2+(j))=*(pointer+k);
j--;
}
else
{
*(pointer2+i)=*(pointer+k);
i++;
}
}
for(i=0;i<n;i++)
printf("%d ",*(pointer2+i));
getch();
}
thaank u
| Is This Answer Correct ? | 6 Yes | 2 No |
Post New Answer View All Answers
.find the output of the following program? char*myfunc(char*ptr) { ptr +=3; return (ptr); } int main() { char*x,*y; x="HELLO"; y=myfunc(x); printf("y = %s ",y); return 0; }
how to build a exercise findig min number of e heap with list imlemented?
How can you read a directory in a C program?
What are structural members?
Why do we use & in c?
Given a valid 24 hour format time find the combination of the value and write a program ,do not hard the value and if any other inputs provided should work with the logic implemented Input: 11:30 Output: 13:10 Input: 18:25 Output: 21:58
How to Throw some light on the splay trees?
Can the curly brackets { } be used to enclose a single line of code?
a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion
What are register variables? What are the advantage of using register variables?
Hai sir, I had planned to write the NIC scientific engineer exam , plz post the sample question......
What is Dynamic memory allocation in C? Name the dynamic allocation functions.
What does main () mean in c?
Can static variables be declared in a header file?
I have a varargs function which accepts a float parameter?