C Program to Find the Array type(odd,even or mixed)

To Find Array type(odd,even or mixed)

In this we will learn to get array type inputted by the user in an array.Here the data enter by user it may be odd, even or mixed depends on the user input.
For Example:-If user enter elements in an array 1,3,5,57,9; then it is called odd type array elements ans so on for the other input by the user.

To find type of array using C
C Program to print type of array

Implementation:-

  1. Enter the size of elements of an array.
  2. Enter the array elements.
  3. If all the elements of the array are odd, display “Odd type array elements”.
  4. If all the elements of the array are even, display “Even type array elements”.
  5. Otherwise, Show “Mixed type array elements”.

C Program:-

// C Code to find the array type (odd,even or mixed array)
#include <stdio.h>
int main()
    {
        int n, j;
        printf("Enter the size of array\n");    //input size of array
        scanf("%d",&n);
        int arr[n];
        printf("Enter the elements of array\n");   //input array elements
        int odd = 0, even = 0;
        for(j = 0; j < n; j++)
        {
            scanf("%d",&arr[j]);
        }
        for(j = 0; j < n; j++)
        {
            if(arr[j] % 2 == 1)
            odd++;
            if(arr[j] % 2 == 0)
            even++;
        }
            if(odd == n)
            printf("Odd type array elements");
            else if(even == n)
            printf("Even type array elements");
            else
            printf("Mixed type array elements");
            return 0;
    }
Output:-
Enter the size of array
3
Enter the elements of array
2
4
8
Even type array elements

Enter the size of array
2
Enter the elements of array
1
2
5
Mixed type array elements