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 / nitin garg
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
{
int num[100],num1[100],n,n1,i,i1=1;
printf("how many elements you enter
");
scanf("%d",&n);
n1=n;
printf("Enter %d elements
",n);
for(i=1;i<=n;i++)
{
scanf("%d",&num[i]);
}
for(i=1;i<=n;i++)
{
if(num[i]==0)
{
num1[i1]=num[i];
i1++;
}
else
{
num1[n1]=num[i];
n1--;
}
}
printf("
Seprate zeor one
");
for(i=1;i<=n;i++)
{
printf("%d ",num1[i]);
}
getch();
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is the size of enum in bytes?
What is function what are the types of function?
How do you define structure?
What are file streams?
What is the stack in c?
What are the types of macro formats?
What is the difference between printf and scanf in c?
How many types of functions are there in c?
Write an algorithm for implementing insertion and deletion operations in a singly linked list using arrays ?
Explain how do you generate random numbers in c?
Explain what are the standard predefined macros?
How can I manipulate strings of multibyte characters?
What are the advantages of using linked list for tree construction?
what are non standard function in c
How can I prevent another program from modifying part of a file that I am modifying?