Program to find even and odd array elements


Prev Tutorial Next Tutorial

Program to find even and odd array elements

For Separate Even and Odd Elements of Array we take three array and one array for insert all Array Elements second for even elements and third for odd elements. We check condition for odd and even Elements arr[]%2==0.

program to find even and odd array elements

#include<stdio.h>
#include<conio.h>

 void main()
  {
   int arr[20],even[20],odd[20],i,j=0,k=0,no;
   clrscr();
   printf("Enter size of array: ");
   scanf("%d",&no);
   printf("Enter any %d elements in Array: ",no);
   for(i=0; i<no;i++)
   {
   scanf("%d",&arr[i]);
   }
   for(i=0; i<no;i++)
   {
   if(arr[i]%2==0)
   {
    even[j]=arr[i];
    j++;
   }
   else
   {
   odd[k]=arr[i];
   k++;
   }
   }
  printf("\nEven Elements: ");
  for(i=0; i<j ;i++)
   {
    printf("%d ",even[i]);
   }
  printf("\nOdd Elements: ");
  for(i=0; i<k; i++)
   {
    printf("%d ",odd[i]);
   }
  getch();
  }

Output

Enter size of array: 5
Enter any 5 elements in Array: 
10 4 5 2 7 
Even Elements: 10 4 2
Odd Elements: 7 5

Prev Tutorial Next Tutorial

Advertisements




Facebook Likes

Advertisements