Skip to content

Instantly share code, notes, and snippets.

@lablnet
Created June 9, 2019 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lablnet/51cc74fbe45e92158817b96908a438cc to your computer and use it in GitHub Desktop.
Save lablnet/51cc74fbe45e92158817b96908a438cc to your computer and use it in GitHub Desktop.
C++ program to fine negative values from array A and B, then put in to Array C in that order C = {9, B, A, 12}
#include <iostream>
using namespace std;
int main()
{
//Default size of array
const int m = 8;
//Loop variables and count to store values in C array
int i, j, k,t = 1;
//Array A
int A[m] = {2,3,4,-5,4,-2,-8,4};
// Array B
int B[m] = {1,2,3,-7,-9,-1,0,1};
//Array C
int C[m] = {9};
//Storing negative values from B to C array
for (i = 1; i < m; i++) {
if (B[i] < 0) {
C[t] = B[i];
t++;
}
}
//Storing negative values from A to C array
for (j = 1; j < m; j++) {
if (A[j] < 0) {
C[t] = A[j];
t++;
}
}
//Putting default value to the end of array
C[t] = 12;
//Printing the value of array C
for (k = 0; k < m; k++) {
cout << C[k] << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment