# C PROGRAMS
Array Programs
➤ Find Length of Array
➤ How to Print an Array
➤ Sum of Array Elements
➤ Reverse an Array in C
➤ Copy an Array in C
➤ Merge Two Arrays in C
➤ Merge Two Sorted Arrays
➤ Count Repeated Elements
➤ Find Duplicate Elements
➤ Linear Search in C
➤ Binary Search in C
➤ Insert Element in Array
➤ Delete Element in Array
➤ Display odd-even in Array
➤ Sum & Count of Odd-Even
➤ Count +ve, -ve, & 0
➤ Sum of +ve, -ve Numbers
➤ Avg & Numbers > Avg
➤ Smallest & Largest Element
➤ 1st 2nd Max-Min
➤ Sort Array in C
➤ Search element in Array
➤ Search index of Nth times occurred element
➤ Matrix Programs
Write a C program to print even and odd numbers in an array. If a number is divisible by 2 then the number is even else the number is odd. To display the even and odd numbers in an array, first of all, initialize array and then check each element of the array.
#include<stdio.h>
int main()
{
int n, a[20];
printf("Enter the size of the array: ");
scanf("%d", &n);
printf("Enter array elements: \n");
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
printf("Even numbers in the array are: \n");
for(int i=0; i<n; i++)
{
if(a[i]%2==0)
printf("%d ", a[i]);
}
printf("\nOdd numbers in the array are: \n");
for(int i=0; i<n; i++)
{
if(a[i]%2!=0)
printf("%d ", a[i]);
}
return 0;
}
Output:-
Enter the size of the array: 5
Enter array elements:
10
15
20
54
26
Even numbers in the array are: 10 20 54 26
Odd numbers in the array are:
15
If you only want to separate the odd and even numbers in an array check the below program.
#include<stdio.h>
int main()
{
int n, a[20];
printf("Enter the size of the array: ");
scanf("%d", &n);
printf("Enter array elements: \n");
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
for(int i=0; i<n; i++)
{
if(a[i]%2==0)
printf("%d: Even\n", a[i]);
else
printf("%d: Odd\n", a[i]);
}
return 0;
}
Output:-
Enter the size of the array: 5
Enter array elements:
10
11
15
48
50
10: Even
11: Odd
15: Odd
48: Even
50: Even
C program to print even and odd numbers in an array using functions
#include<stdio.h>
void findEvenNumbers(int a[], int size)
{
for(int i=0; i<size; i++)
{
if(a[i]%2 == 0)
printf("%d ", a[i]);
}
}
void findOddNumbers(int a[], int size)
{
for(int i=0; i<size; i++)
{
if(a[i]%2 != 0)
printf("%d ", a[i]);
}
}
int main()
{
int n, a[20];
printf("Enter the size of the array: ");
scanf("%d", &n);
printf("Enter array elements: \n");
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
printf("Even numbers in the array are: \n");
findEvenNumbers(a, n);
printf("\nOdd numbers in the array are: \n");
findOddNumbers(a, n);
return 0;
}
Output:-
Enter the size of the array: 5
Enter array elements:
11
12
13
15
18
Even numbers in the array are: 12 18
Odd numbers in the array are: 11 13 15
In this program, we created two user-defined functions find Even Numbers and find Odd Numbers. The find Even Numbers finds the even number from the array and similarly, the user-defined function finds Odd Numbers find the odd number from the array.
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!
Follow Us
Instagram • Twitter • Youtube • Linkedin • Facebook • Pinterest • Telegram
Similar C programming examples on Arrays
- Sum of Array elements
- Display even & odd numbers in an array
- Sum and count of even and odd numbers in an array
- Count positive negative and zeros in the array
- Sum of positive and negative numbers
- Average and numbers greater than average in the array
- Find Smallest and largest Array element
- First maximum & minimum, Second maximum & minimum
- Sort a list of an array element
- Search an Array element
- Search position of nth times occurred element in an array
- C program to insert an element in an array
- C program to delete an element in an array
- Passing a multidimensional array to Function
- Find Largest and smallest in a 2D array with their position
- Store temperature of two Cities for a week & display
- Matrix Operations – Addition, Multiplication, Transpose
I’m delighted that I came across this site, the information shared is excellent for a student in South Africa.