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
Explain about block scope in c?
What is the value of uninitialized variable in c?
What is the meaning of c in c language?
What is the correct declaration of main?
Is c still relevant?
What are comments and how do you insert it in a C program?
What are the advantages of using Unions?
Do you know the difference between malloc() and calloc() function?
int i=10; printf("%d %d %d", i, i=20, i);
What is the difference between printf and scanf )?
What is the collection of communication lines and routers called?
Who invented b language?
List the difference between a "copy constructor" and a "assignment operator"?
What is typeof in c?
Is main a keyword in c?