Skip to content

Instantly share code, notes, and snippets.

@Lablnet Lablnet/program.cpp
Created Jun 9, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.