w3resource
C Programming Exercises

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

C-programming basic algorithm: Exercise-41 with Solution

Write a C program to check if a given array of integers and length 2, contains 15 or 20.

C Code:

#include <stdio.h>
#include <stdlib.h>
int main(void){
    int arr_size;
    int array1[] = {12, 20};
    printf("%d",test(array1));
    int array2[] = {14, 15};
    printf("\n%d",test(array2));
    int array3[] =  {11, 21};
    printf("\n%d",test(array3));
    }       
    int test(int nums[])
         {
             return nums[0] == 12 || nums[0] == 15 || nums[1] == 12 || nums[1] == 15;
        }

Sample Output:

1
1
0

Flowchart:

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

Solution

Contribute your code and comments through Disqus.

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 if a given array of integers and length 2, does not contain 15 or 20.



New Content: Composer: Dependency manager for PHP, R Programming