Find the type of the array

Problem statement:- Program to Find the type of array.

Data requirement:-

   Input Data:- arr, size

  Output Data:-String output

  Additional Data:- i, j, odd_type,even_type

Program in C

Here is the source code of the C Program to Find the type of the array.

Code:

#include<stdio.h>
main()
{
    printf("Enter the size of the array:");
    int size;
    scanf("%d",&size);
    int arr[size];
    int i,odd_type=0,even_type=0;
    printf("Enter the Element of the array:\n");
    for(i=0;i<size;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=0;i<size;i++)
    {
        if(arr[i]%2==0)
            even_type++;
        else
            odd_type++;
    }
    if(even_type==size)
        printf("Even type array\n");
    else if(odd_type==size)
        printf("odd type array\n");
    else
        printf("Mixed array\n");
}

Input/Output:
Enter the size of the array:4
Enter the Element of the array:
6
8
10
12
Even type array

Program in C++

Here is the source code of the C++ Program to Find the type of the array.

Code:

#include<iostream>
using namespace std;
main()
{
    cout<<"Enter the size of the array:";
    int size;
    cin>>size;
    int arr[size];
    int i,odd_type=0,even_type=0;
    cout<<"Enter the Element of the array:\n";
    for(i=0;i<size;i++)
    {
        cin>>arr[i];
    }
    for(i=0;i<size;i++)
    {
        if(arr[i]%2==0)
            even_type++;
        else
            odd_type++;
    }
    if(even_type==size)
        cout<<"Even type array\n";
    else if(odd_type==size)
        cout<<"odd type array\n";
    else
        cout<<"Mixed array\n";
}

Input/Output:
Enter the size of the array:5
Enter the Element of the array:
7
11
3
13
97
odd type array

Program in Java

Here is the source code of the Java Program to Find the type of the array.

Code:

import java.util.Scanner;
public class p24 {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the size of the array:");
int i,odd_type=0,even_type=0,size;
    size=sc.nextInt();
    int arr[ ]=new int[size];
System.out.println("Enter the Element of the array:");
     for(i=0;i<size;i++)
    {
        arr[i]=sc.nextInt();
    }
     System.out.print("\nArray elements are:");
     for(i=0;i<size;i++)
     {
    System.out.print(arr[i]+" ");
     }
     for(i=0;i<size;i++)
     {
         if(arr[i]%2==0)
             even_type++;
         else
             odd_type++;
     }
     if(even_type==size)
    System.out.println("\nEven type array");
     else if(odd_type==size)
    System.out.println("\nodd type array");
     else
    System.out.println("\nMixed array");      
           sc.close();
}
}

Input/Output:
Enter the size of the array:
5
Enter the Element of the array:
4
3
9
11
15

Array elements are:4 3 9 11 15 
Mixed array

Program in Python

Here is the source code of the Python Program to Find the type of the array.

Code:

arr=[]
odd_type=0
even_type=0
size = int(input("Enter the size of the array: "))
print("Enter the Element of the array:")
for i in range(0,size):
    num = int(input())
    arr.append(num)
print("Array elements are:")
for i in range(0,size):
    print(arr[i],end=" ")
for i in range(0,size):
    if arr[i] % 2 == 0:
        even_type +=1
    else:
        odd_type +=1
if even_type==size:
        print("\nEven type array")
elif odd_type==size:
        print("\nodd type array")
else:
        print("\nMixed array")

Input/Output:
Enter the size of the array: 5
Enter the Element of the array:
4
44
84
102
3044
Array elements are:
4 44 84 102 3044 
Even type array

Post a Comment

0 Comments