Functions – Array type
Write a program to find the type of array using functions. An array is said to be "Even" if all the elements in the array are even. An array is said to be "Odd" if all the elements in the array are odd. An array is said to be "Mixed" if it contains some odd elements and some even elements. Refer function specifications for the function details. The first argument corresponds to the number of elements in the array. The second argument corresponds to the pointer to an array. The return value of the function should be 1 if the array is Even. The return value of the function should be 2 if the array is Odd. The return value of the function should be 3 if the array is Mixed.
Answers
Answered by
3
Answer:
#include<iostream>
using namespace std;
int main()
{
//fill your code
int n;
cin >> n;
int arr[n];
for(int i = 0; i < n; i++)
{
cin >> arr[i];
}
int i;
int odd = 0, even = 0;
for(i = 0; i < n; i++)
{
if(arr[i] % 2 == 1)
odd++;
if(arr[i] % 2 == 0)
even++;
}
if(odd == n)
cout << “Odd”;
else if(even == n)
cout << “Even”;
else
cout << “Mixed”;
return 0;
}
output
5
1 2 3 4 5
Mixed
Explanation:
Similar questions
Hindi,
5 months ago
English,
5 months ago
Physics,
11 months ago
Math,
1 year ago
Business Studies,
1 year ago