Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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



array contains zeros and ones as elements.we need to bring zeros one side and one other side in si..

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

array contains zeros and ones as elements.we need to bring zeros one side and one other side in si..

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

Post New Answer

More C Interview Questions

illustrate the use of address operator and dereferencing operator with the help of a program guys plzzz help for this question

0 Answers  


There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?

0 Answers  


what is array?

8 Answers  


You have given 2 array. You need to find whether they will create the same BST or not. For example: Array1:10 5 20 15 30 Array2:10 20 15 30 5 Result: True Array1:10 5 20 15 30 Array2:10 15 20 30 5 Result: False One Approach is Pretty Clear by creating BST O(nlogn) then checking two tree for identical O(N) overall O(nlogn) ..we need there exist O(N) Time & O(1) Space also without extra space .Algorithm ?? DevoCoder guest Posted 3 months ago # #define true 1 #define false 0 int check(int a1[],int a2[],int n1,int n2) { int i; //n1 size of array a1[] and n2 size of a2[] if(n1!=n2) return false; //n1 and n2 must be same for(i=0;i<n1-1;i++) { if( !( (a1[i]>a1[i+1]) && (a2[i]>a2[i+1]) ) ) return false; } return true;//assumed that each array doesn't contain duplicate elements in themshelves }

0 Answers   Facebook,


what is printf

5 Answers   MVSR, Satyam,


what is the value of b if a=5; b=++a + ++a

31 Answers   Infosys, TCS, Tech Mahindra,


What is c programing language?

0 Answers  


how is the examination pattern?

0 Answers   Wipro,


What is equivalent to ++i+++j?

0 Answers  


How do I get an accurate error status return from system on ms-dos?

0 Answers  


How to avoid buffer overflow?

1 Answers  


Explain void pointer?

0 Answers  


Categories