w3resource

C Exercises: Check whether a given array of integers of length 2, contains 15 or 20


41. Array of Two: Check for 15 or 20

Write a C program to check whether an array of integers with a length of 2 contains 15 or 20.

C Code:

#include <stdio.h>
#include <stdlib.h>

// Function prototype for 'test'
int test(int nums[]);

int main(void){
    // Declaration and initialization of variables
    int arr_size;
    int array1[] = {12, 20};

    // Printing the result of calling 'test' function with different arrays
    printf("%d", test(array1));

    int array2[] = {14, 15};
    printf("\n%d", test(array2));

    int array3[] =  {11, 21};
    printf("\n%d", test(array3));
}       

// Definition of the 'test' function
int test(int nums[])
{
    // Checking if any of the elements in the array are equal to 12 or 15
    return nums[0] == 12 || nums[0] == 15 || nums[1] == 12 || nums[1] == 15;
}

Sample Output:

1
1
0

Pictorial Presentation:

C Programming Algorithm: Check whether a given array of integers of length 2, contains 15 or 20

Flowchart:

C Programming Algorithm Flowchart: Check whether a given array of integers of length 2, contains 15 or 20

For more Practice: Solve these Related Problems:

  • Write a C program to verify if an array of length 2 contains 25 or 30.
  • Write a C program to check if an array of two integers contains any prime number.
  • Write a C program to determine if one of the two elements in an array is a multiple of 5.
  • Write a C program to check if an array of two integers contains either 10 or 20 exclusively.

Go to:


PREV : New Array from First and Last Elements.
NEXT : Array of Two: Exclude 15 and 20.

C Programming Code Editor:



What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.