Tutorials, Free Online Tutorials,It Challengers provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, core java, sql, php, c language etc. for beginners and professionals.

Breaking

Write a c program to find Even and Odd Elements from Array

Program To Find Even and Odd Elements From Array

#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:-

No comments:

Post a Comment