Write a program to count the total number of even and odd elements in an array

Write a program to count the total number of even and odd elements in an array

  1. #include <stdio.h>

  2. int main()
  3. {
  4.     int arr[100];
  5.     int i, n;
  6.     int even=0, odd=0;

  7.     printf("Enter the number to be stored in the array : ");
  8.     scanf("%d", &n);

  9.     printf("Enter %d elements in the array : ", n);
  10.     for(i=0; i<n; i++) {
  11.         scanf("%d", &arr[i]);
  12.     }

  13.     for(i=0; i<n; i++) {
  14.         if(arr[i]%2 == 0) {
  15.             even++;
  16.         }
  17.         else {
  18.             odd++;
  19.         }
  20.     }

  21.     printf("Total even elements: %d\n", even);
  22.     printf("Total odd elements: %d", odd);

  23.     return 0;
  24. }

একটি মন্তব্য পোস্ট করুন