C program to find array type entered by user
Question
Write a C program to find the array type that needs to be checked to determine whether the elements in a given array are even or odd, or both have.
Solution
The user needs to input an integer array and then display the type of the array.
Example 1 − Input: 5 3 1, output: odd array.
Example 2 − Input: 2 4 6 8, output: even array.
Example 3 − Input: 1 2 3 4 5, output: mixed array.
Algorithm
Refer to the algorithm given below to find the array type entered by the user.
Step 1 − Read the size of the array at runtime.
Step 2 − Enter the array elements.
Step 3 − If all elements of the array are odd, print "odd".
Step 4 − If all elements of the array are even numbers, print "even".
Step 5 − Otherwise, print "Mixed".
Example
The following is a C program to find the array type entered by the user−
Demonstration
#include<stdio.h> int main(){ int n; printf("enter no of elements:"); scanf("%d",&n); int arr[n]; int i; int odd = 0, even = 0; printf("enter the elements into an array:</p><p>"); for(i = 0; i < n; i++){ scanf("%d",&arr[i]); } for(i = 0; i < n; i++){ if(arr[i] % 2 == 1) odd++; if(arr[i] % 2 == 0) even++; } if(odd == n) printf("Odd Array"); else if(even == n) printf("Even Array"); else printf("Mixed Array"); return 0; }
Output
When the above When the program is executed, it produces the following output −
Run 1: enter no of elements:5 enter the elements into an array: 2 4 8 10 12 Even Array Run 2: enter no of elements:5 enter the elements into an array: 1 23 45 16 68 Mixed Array
The above is the detailed content of C program to find array type entered by user. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Use the Array.IndexOf function in C# to find the index of an element in an array. In a C# program, when we need to find the index of an element in an array, we can use the Array.IndexOf function. The Array.IndexOf function finds the specified element within the specified array range and returns the index of its first occurrence. If the element is not found, -1 is returned. The following is a sample code that demonstrates how to use the Array.IndexOf function to find an element in an array.

What happens when you turn off Find My on iPhone? Find My iPhone helps you locate a lost or stolen device. When enabled, Find My iPhone lets you track your device's location on a map, plays sounds, and helps you find your device. Find My also includes an Activation Lock to prevent anyone from using your iPhone. When you turn off Find My iPhone, you lose all these features, which may make recovering a lost Apple device difficult. While Find My iPhone is very useful, you should disable it when you want to sell, donate, trade in your phone, or send it for battery replacement or any other service. Doing this will ensure that no one can access information about you

Hard drive serial numbers and MAC addresses are important identifiers in computer hardware and are very useful in managing and maintaining computer systems. This article will introduce how to find the hard disk serial number and MAC address. 1. Find the hard drive serial number. The hard drive serial number is a unique identifier used by the hard drive manufacturer to identify and track the hard drive. In different operating systems, the method of finding the hard drive serial number is slightly different. Windows: Open Command Prompt (search for "cmd" in the Start menu) and enter the following command and press Enter: wmicdisk

Apple's Find My app allows you to locate your iPhone or other device to prevent it from being lost or forgotten. While Find My is a useful tool for tracking devices, you may want to disable it if you're concerned about privacy issues, don't want to drain your battery, or for other reasons. Fortunately, there are several ways to turn off Find My on iPhone, all of which we will explain in this article. How to Turn off Find My on iPhone [4 Methods] You can turn off Find My on iPhone in four ways. If you used Method 1 to turn off Find, you can do this from the device you want to disable it on. To proceed with methods 2, 3, and 4, the iPhone that you want to turn off Find Finder should be powered off or

In Python, there are several ways to input a string from the user. The most common way is to use the built-in function input(). This function allows the user to enter a string, which is then stored as a variable for use by the program. Example Below is an example of inputting a string from the user in Python −#Defineavariabletostoretheinputname=input("Pleaseenteryourname:")#Printtheinputprint("Hello,"+name+"!Goodtoseeyou.&qu

The glob() function in PHP is used to find files or directories and is a powerful file operation function. It can return the path of a file or directory based on a specified pattern match. The syntax of the glob() function is as follows: glob(pattern, flags) where pattern represents the pattern string to be matched, which can be a wildcard expression, such as *.txt (matching files ending with .txt), or a specific file path. flags is an optional parameter used to control the function

How to Check the Serial Number of a Computer Hard Drive With the development of computer technology, computer hard drives have become an indispensable part of our lives. Whether it is storing important files or installing operating systems and software, you need to rely on the hard disk to complete it. Understanding some basic information about the computer hard drive, such as the hard drive's serial number, can help us better manage and maintain the computer system. So, how to check the serial number of a computer hard drive? This article will introduce several common methods. Method 1: Use the command line tool that comes with Windows system Windows system

In this problem, we are given an array aar[] containing n unsorted integer values and an integer val. Our task is to find the start and end index of an element in an unsorted array. For occurrences of an element in the array, we will return, "start index and end index" (if found twice or more in the array). "Single index" (if found) "Element does not exist" if not present in the array. Let us take an example to understand the problem, Example 1Input:arr[]={2,1,5,4,6,2,3},val=2Output:startingindex=0,endingindex=5 explains that element 2 appears twice, The first time appears at index = 0, the second
