Description about Program to find the array type
Get an array as input from the user and check the type of the array, whether it is odd, even or mixed type.
Input
Enter size of array:
3
Enter elements
1 3 5
Output
Odd
C Program to find the array type
#include<stdio.h>
int main()
{
int n;
printf("Enter the size of the array: ");
scanf("%d",&n);
int arr[n];
int i;
int o=0, e=0;
printf("Enter the array elements: ");
for(i = 0; i < n; i++)
{
scanf("%d",&arr[i]);
}
for(i = 0; i < n; i++)
{
if(arr[i] % 2 == 1)
o++;
if(arr[i] % 2 == 0)
e++;
}
if(o == n)
printf("Odd");
else if(e == n)
printf("Even");
else
printf("Mixed");
return 0;
}
C++ Program to find the array type
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter the size of the array: ";
cin>>n;
int arr[n];
int i;
int o=0, e=0;
cout<<"Enter the array elements: ";
for(i = 0; i < n; i++)
{
cin>>arr[i];
}
for(i = 0; i < n; i++)
{
if(arr[i] % 2 == 1)
o++;
if(arr[i] % 2 == 0)
e++;
}
if(o == n)
cout<<"Odd";
else if(e == n)
cout<<"Even";
else
cout<<"Mixed";
return 0;
}
Java Program to find the array type
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int n;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of the array: ");
n = sc.nextInt();
int[]arr = new int[n];
System.out.println("Enter the array elements: ");
for(int i = 0; i < n; i++)
{
arr[i] = sc.nextInt();
}
int o =0, e = 0;
for(int i = 0; i < n; i++)
{
if(arr[i] % 2 == 1)
o++;
else
e++;
}
if(o == n)
System.out.print("Odd");
else if(e == n)
System.out.print("Even");
else
System.out.print("Mixed");
}
}
Python Program to find the array type
n = int(input("Enter size of array: "))
arr = []
print("Enter array elements: ")
for i in range(0,n):
temp = int(input())
arr.append(temp)
o = 0
e = 0
for i in range(0,n):
if(arr[i] % 2 == 1):
o = o + 1
else:
e = e + 1
if(o == n):
print("Odd")
elif(e == n):
print("Even")
else:
print("Mixed");