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 / rizwan
This program will work perfectly. I hope this is the exact
answer to the question.
#include<stdio.h>
void swap(int *a, int *b)
{
int temp;
temp = *b;
*b=*a;
*a=temp;
}
int main()
{
int a[]={0,0,1,0,1,1,0,0};
int i,j;
for(i=0;i<8;i++)
{
if(a[i])
{
j=i+1;
while(j<8)
{
j++;
if(!a[j])
{
swap(&a[i],&a[j]);
break;
}
}
}
}
for(i=0;i<8;i++)
printf("%d ",a[i]);
return;
}
| Is This Answer Correct ? | 6 Yes | 1 No |
Post New Answer View All Answers
What are the disadvantages of a shell structure?
What is a rvalue?
How many levels of pointers have?
Why is it important to memset a variable, immediately after allocating memory to it ?
What is the scope of local variable in c?
Why is c still so popular?
regarding pointers concept
What are types of functions?
How will you find a duplicate number in a array without negating the nos ?
int far *near * p; means
What is meant by inheritance?
When do you not use the keyword 'return' when defining a function a) Always b) Never c) When the function returns void d) dfd
What is pragma in c?
Write a C program to help a HiFi’s Restaurant automate its breakfast billing system. Your assignment should implement the following items: a. Show the customer the different breakfast items offered by the HiFi’s Restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill to the customer. d. Produce a report to present your complete program and show more sample output. Assume that the HiFi’s Restaurant offers the following breakfast menu: Plain Egg $2.50 Bacon and Egg $3.45 Muffin $2.20 French Toast $2.95 Fruit Basket $3.45 Cereal $0.70 Coffee $1.50 Tea $1.80
What is the g value paradox?