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
How pointers are declared?
What is return in c programming?
What’s the special use of UNIONS?
Are the variables argc and argv are always local to main?
What does != Mean in c?
Difference between linking and loading?
Mention four important string handling functions in c languages .
shorting algorithmS
Explain the term printf() and scanf() used in c language?
Is boolean a datatype in c?
What is the method to save data in stack data structure type?
What are the 4 types of unions?
Can main () be called recursively?
I came across some code that puts a (void) cast before each call to printf. Why?
What is sizeof return in c?