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
Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop
regarding pointers concept
How can I write a function that takes a format string and a variable number of arguments?
What are the different file extensions involved when programming in C?
What are different types of variables in c?
Is printf a keyword?
What is the function of this pointer?
What is the equivalent code of the following statement in WHILE LOOP format?
What is use of null pointer in c?
a way in which a pointer stores the address of a pointer which stores the value of the target value a) reference b) allocation c) multiple indirection d) none
What's the right way to use errno?
What is a nested formula?
What is conio h in c?
Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
Difference between macros and inline functions? Can a function be forced as inline?