











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.




Implementation:-
- Enter the size of elements of an array.
- Enter the array elements.
- If all the elements of the array are odd, display “Odd type array elements”.
- If all the elements of the array are even, display “Even type array elements”.
- 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
Login/Signup to comment