Counting Even and Odd Integers in an array in C


This program is a simple program that takes a string as input and counts the number of alphabets, digits and special characters in the string.

The program starts by including the stdio.h header file, which contains the declarations of the functions used in the program.

In the main function, the program declares a character array "str" of size 100 , an integer variable "i" for the loop, an integer variable "a" to store the count of alphabets, an integer variable "d" to store the count of digits, and an integer variable "s" to store the count of special characters.

It uses the printf function to prompt the user to enter the string and uses the gets function to read the input and store it in the "str" array.

The program then uses a for loop to iterate through the string. Inside the loop, it uses if-else statements to check if the current character is an alphabet, a digit, or a special character. The check is done by comparing the ASCII value of the current character with the range of ASCII values of alphabets, digits and special characters . If the current character is an alphabet, it increments the variable a. If it's a digit, it increments the variable d, otherwise it increments the variable s.

Finally, the program uses the printf function to print out the total number of alphabets, digits, and special characters and returns 0 to indicate that the program has executed successfully

Source Code

//Program to find total no of even and odd numbers in an array in C Programming.
 
#include<stdio.h>
 
int main()
{
    int a[100],i,n,e=0,o=0;
    printf("\nEnter The Limit : ");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("\nEnter The Value : ");
        scanf("%d",&a[i]);
        a[i]%2==0?e++:o++;
        /*if(a[i]%2==0)
        {
            e++;
        }
        else
        {
            o++;
        }*/
    }
    printf("\nTotal Even No is : %d",e);
    printf("\nTotal Odd  No is : %d",o);
     return 0;
}
 
To download raw file Click Here

Output

Enter The Limit : 6

Enter The Value : 3

Enter The Value : 21

Enter The Value : 45

Enter The Value : 2

Enter The Value : 678

Enter The Value : 91

Total Even No is : 2
Total Odd  No is : 4

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C