- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C program to find type of array entered by the user.
Problem
Write a C Program to find the array type which we need to check, whether the given elements in an array are even numbers or odd numbers or combination of both.
Solution
So, user has to enter an array of integers, 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 an algorithm given below to find the array type entered by the user.
Step 1 − Read the size of array at runtime.
Step 2 − Input the array elements.
Step 3 − If all the elements of the array are odd, Then, print "Odd".
Step 4 − If all the elements of the array are even, Then, print "Even".
Step 5 − Else, print "Mixed".
Example
Following is the C program to find the array type entered by the user −
#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:
"); 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 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
- Related Articles
- C program to find array type entered by user using pointers.
- C++ Program to Print Number Entered by User
- C Program to check the type of character entered
- Program to find out the data type of user input in C++
- C# Program to display the Factors of the Entered Number
- C# program to display factors of entered number
- C/C++ Program to Find the reminder of array multiplication divided by n?
- C/C++ Program to Find reminder of array multiplication divided by n ?
- C++ program to find the type of the given iterator
- C++ Program to find kth Smallest Element by the Method of Partitioning the Array
- C# Program to Count the Number of 1's in the Entered Numbers
- C++ set for user define data type
- C++ set for user defined data type?
- Write a C# program to check if the entered number is Armstrong number?
- Java Program to fill an array of characters from user input
