C Tutorial
This c program is used to find the number of even elements occurrences in integer array using for loop and if statement.
#include<stdio.h> void main() { int numbers[10], i, n, count=0; printf("Enter number of elements:\n"); scanf("%d", &n); /* Reading array elements */ printf("\nInput %d values: ", n); for(i=0; i<n; i++) { scanf("%d", &numbers[i]); } for(i=0;i<n;i++) { if(numbers[i]%2==0) { count = count + 1; } } printf("\nEven Elements count in array: %d", count); }
Output:
$ cc even_elements_occurrence.c ]$ ./a.out Enter number of elements: 5 Input 5 values: 21 34 62 58 11 Even Elements count in array: 3[
This c program is used to find the number of even elements occurrences and also finds array index location's where even elements are available using for loop and if statements.
#include<stdio.h> void main() { int numbers[10], i, n, count=0, occurrence[10]; printf("Enter number of elements:\n"); scanf("%d", &n); /* Reading array elements */ printf("\nInput %d values: ", n); for(i=0; i<n; i++) { scanf("%d", &numbers[i]); occurrence[i] = 0; } for(i=0;i<n;i++) { // Checks whether array element is even or not if(numbers[i]%2==0) { occurrence[i] = 1; count = count + 1; } } printf("\nEven Element count in array: %d", count); printf("\nOccurrence of even element index's in array: "); for(i=0;i<n;i++) { if(occurrence[i]==1) { printf("%d\t",i); } } }
Output:
$ cc even_elements_occurrence.c $ ./a.out Enter number of elements: 5 Input 5 values: 12 3 45 56 22 Even Element count in array: 3 Occurrence of even element index's in array: 0 3 4
C Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page