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
Does sprintf put null character?
How can I run c program?
How do we make a global variable accessible across files? Explain the extern keyword?
What is the difference between text files and binary files?
Why c is called object oriented language?
What is the use of parallelize in spark?
What is strcmp in c?
What is context in c?
How can I manipulate strings of multibyte characters?
Why we use void main in c?
How can you find the exact size of a data type in c?
Why is c fast?
What is dynamic memory allocation?
Differentiate fundamental data types and derived data types in C.
Why does everyone say not to use gets?