Wednesday 12 August 2015

C Program to read array of elements and print only even numbers


Program:

#include< stdio.h >
#include< conio.h >
void main( )
{
         int i, a[10];
         for( i = 0; i < 5; i++ )
         {
                    printf("Enter the value for a[ %d ]: ", i);
                    scanf("%d", &a[ i ]);
          }
          printf("\nThe array of Even elements are:\n");
          for( i = 0; i < 5; i++ )
          {
                    if( a[ i ] % 2 == 0 )
                    {
                               printf(" %d ", a[ i ] );
                     }
           }
}


Output:

Enter the value for a[ 0 ]: 1

Enter the value for a[ 1 ]: 2

Enter the value for a[ 2 ]: 3

Enter the value for a[ 3 ]: 4

Enter the value for a[ 4 ]: 5

The array of Even elements are:

2 4








0 comments:

Post a Comment