C Exercises: Check whether a given array of integers of length 2, contains 15 or 20
C-programming basic algorithm: Exercise-41 with Solution
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:
Flowchart:

C Programming Code Editor:
Previous: Write a C program to create a new array taking the first and last elements of a given array of integers and length 1 or more.
Next: Write a C program to check whether a given array of integers of length 2, does not contain 15 or 20.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join