A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a C++ program to separate 0s and 1s from a given array of values 0 and 1
Q:

Write a C++ program to separate 0s and 1s from a given array of values 0 and 1

0

Write a C++ program to separate 0s and 1s from a given array of values 0 and 1

Sample Output:

Original array: 0 1 0 0 1 1 1 0 1 0 
Array after divided: 0 0 0 0 0 1 1 1 1 1

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
using namespace std;
 

void segregateEvenOdd(int nums[], int n)
{
    int ctr = 0;  
 
    for (int i = 0; i < n; i++) {
        if (nums[i] == 0)
            ctr++;
    }
 
   for (int i = 0; i < ctr; i++)
        nums[i] = 0;
 
   for (int i = ctr; i < n; i++)
        nums[i] = 1;
}
 
int main()
{
    int nums[] = {0, 1, 0, 0 , 1, 1, 1, 0, 1, 0};
    int n = sizeof(nums)/sizeof(nums[0]);
   	cout << "Original array: ";
    for (int i=0; i < n; i++) 
    cout << nums[i] <<" ";
    segregateEvenOdd(nums, n);
 
    printf("\nArray after divided: ");
      for (int i=0; i < n; i++) 
      cout << nums[i] <<" ";
        return 0;     
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now