Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C++ Exercises: Check if a given array of integers and length 2, does not contain 15 or 20

C++ Basic Algorithm: Exercise-90 with Solution

Write a C++ program to check if a given array of integers and length 2, does not contain 15 or 20.

Sample Solution:

C++ Code :

#include <iostream>

using namespace std;

bool test(int nums[]) {
    return nums[0] != 15 && nums[0] != 20 && nums[1] != 15 && nums[1] != 20;
    }

int main () {
  int nums1[] = { 12, 20 }; 
  int nums2[] = { 14, 15 };
  int nums3[] = { 11, 21 };
  cout << test(nums1) << endl;
  cout << test(nums2) << endl;
  cout << test(nums3) << endl;    
   return 0;
}

Sample Output:

0
0
1

Pictorial Presentation:

C++ Basic Algorithm Exercises: Check if a given array of integers and length 2, does not contain 15 or 20.

Flowchart:

Flowchart: Check if a given array of integers and length 2, does not contain 15 or 20.

C++ Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a C++ program to check if a given array of integers and length 2, contains 15 or 20.
Next: Write a C++ program to check a given array of integers and return true if the array contains 10 or 20 twice. The length of the array will be 0, 1, or 2.

What is the difficulty level of this exercise?