C Tutorial
This c program is used to find the number of odd 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==1) { count = count + 1; } } printf("\nOdd Element count in array: %d", count); }
Output:
$ cc odd_elements_occurrence.c $ ./a.out Enter number of elements: 5 Input 5 values: 23 45 21 46 13 Odd Element count in array: 4
This c program is used to find the number of odd elements occurrences and also finds array index location's where odd 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++) { if(numbers[i]%2==1) { occurrence[i] = 1; count = count + 1; } } printf("\nOdd Element count in array: %d", count); printf("\nOccurrence of odd element index's in array: "); for(i=0;i<n;i++) { if(occurrence[i]==1) { printf("%d\t",i); } } }
Output:
$ cc odd_elements_occurrence.c $ ./a.out Enter number of elements: 5 Input 5 values: 23 41 22 14 57 Odd Element count in array: 3 Occurrence of odd element index's in array: 0 1 4
C Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page