In this tutorial you will learn about the C Program to Count Even Odd and its application with practical example.
C Program to Count Even Odd
In this tutorial, we will learn to create a C program that will Count Even Odd in Array using C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- For loop in C programming.
- Conditional Statements in C programming.
- Arithmetic operations in C Programming.
Program to Count Even Odd in Array
In c programming, it is possible to take numerical input from the user and Count Even Odd with the help of a very small amount of code. The C language has many types of header libraries which has supported function in them with the help of these files the programming is easy.
The Count Even-Odd, Even numbers are those numbers that are completely divisible by 2. which means the reminder should be zero. And odd numbers are those numbers that cannot be completely divisible by 2.
With the help of this program, we can Count Even Odd in Array.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 |
1. Declaring the variables for the program. 2. Taking the input size of the array from the user. 3. Taking the elements of the array. 4. Counting the <strong>Even & Odd </strong>numbers from the array. 5. Printing the result numbers. 6. End Program. |
Program to Count Even Odd in Array:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
/* C Program that will Count the Even and Odd Numbers in an Array */ #include<stdio.h> int main() { //declaring the variables for the program int Size, i, arr[10]; int EvenNo = 0, OddNo = 0; //taking input size of the array from the user printf("\n Please Enter the Size of an Array : "); scanf("%d", &Size); //taking the array elements from the user printf("\nPlease Enter the Array Elements\n"); for(i = 0; i < Size; i++) { scanf("%d", &arr[i]); } //counting the even and odd numbers from the array for(i = 0; i < Size; i ++) { if(arr[i] % 2 == 0) { EvenNo++; } else { OddNo++; } } // printing the output number of even and odds printf("\n Total Number of Even Numbers in this Array = %d ", EvenNo); printf("\n Total Number of Odd Numbers in this Array = %d ", OddNo); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- arr[10]= it will hold the integer value.
- i = it will hold the integer value.
- Size= it will hold the integer value.
- EvenNo = it will hold the integer value.
- OddNo= it will hold the integer value.
Input size and elements of the array.
Program Logic Code.
Printing output Count Even Odd in Array.