Interview Questions   Tutorials   Discussions   Programs   

C - Write a program to find the number of even integers and odd integers in a given array in c language?




242
views
asked marvit August 18, 2014 08:49 AM  

Write a program to find the number of even integers and odd integers in a given array in c language?


           

1 Answers



 
answered By bhjahnavi   0  
/* program to find even and odd number in an array*/
#include <stdio.h>
 
void main()
{
  int array[100], i, num;
 
  printf("Enter the size of an array \n");
  scanf("%d", &num);
  printf("Enter the elements of the array \n");
  for (i = 0; i < num; i++)
  {
    scanf("%d", &array[i]);
  }
  printf("Even numbers in the array are - ");
  for (i = 0; i < num; i++)
  {
    if (array[i] % 2 == 0)
    {
      printf("%d \t", array[i]);
    }
  }
  printf("\n Odd numbers in the array are -");
  for (i = 0; i < num; i++)
  {
    if (array[i] % 2 != 0)
    {
      printf("%d \t", array[i]);
    }
  }
}

output:
Enter the size of an array
6
Enter the elements of the array
12
19
45
69
98
23
Even numbers in the array are - 12     98
 Odd numbers in the array are - 19     45     69     23
flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert