Thursday 8 January 2015

C Program to find all the Even and Odd numbers in an array


This is a C Program which finds the even and odd numbers in an array.

Here all the elements in the array are checked for even and odd condition , when the condition satisfies it prints out the result

PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,n;
    printf("How many elements ?\t");     
    scanf("%d",&n); 
    int a[n];
    for(i=0;i<n;i++)                    
    {
        printf("Enter number %d \t",i+1);
        scanf("%d",&a[i]);
    }
    printf("\nThe Even Numbers are : \t");   
    for(i=0;i<n;i++)
    {

        if(a[i]%2 == 0)
            printf("%d \t",a[i]);

    }
    printf("\nThe Odd Numbers are : \t");  
    for(i=0;i<n;i++)
    {

        if(a[i]%2 != 0)
            printf("%d \t",a[i]);

    }
    return 0;
}

OUTPUT :
C - Even and Odd Elements in an Array
Related Programs:

No comments:

Post a Comment