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}
Answers were Sorted based on User's Feedback
Answer / manoj
#include<stdio.h>
#include<conio.h>
void main()
{
int a[]={0,0,1,0,1,1,0,0};
int *arrayTemp = a;
int i, j_0 = 0, j_8 = 8;
for(int data = 0; *a != '\0'; *a++)
{
data = *a;
if(data == 1 )
{
a[j_0++] = data;
}
else
{
a[j_8--] = data;
} // if-else block
}//for loop
}//main function
for(i=0; i< 8; i ++)
{
printf("array value is %d", a[i]);
}
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / 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 |
Which programming language is best for getting job 2020?
How do I get an accurate error status return from system on ms-dos?
Define C in your own Language.
What is auto keyword in c?
What is string constants?
Explain #pragma in C.
which is the best site or book for learning C...and i need the content for C..how to get the good programming skills....? can plz suggest me....
let's take a code struct FAQ { int a; char b; float c; double d; int a[10]; }*temp; now explain me how the memory will be allocated for the structure FAQ and what address will be in the structure pointer (temp)....................
What is the real difference between arrays and pointers?
27 Answers Hexaware, Logic Pro, TCS,
Differentiate between the = symbol and == symbol?
What is sorting in c plus plus?
write a program that print itself even if the source file is deleted?