CREATE OWN LIBRARY

Finds odd and even elements from the array and stored in two separate arrays

Back to Programming

Description

The elements of the array are taken as input. The program finds out the odd and even elements from the array and stores in two separate arrays.

 

Algorithm

INPUT: Array elements
OUTPUT: the two arrays containing odd and even numbers separately
PROCESS:
Step 1: [taking the input]
	Read n [number of elements]
	For i=0 to n-1 repeat
		Read a[i]
	[end of ‘for’ loop]
Step 2: [separating the odd and even elements into two separate arrays]
	Set o<-0
	Set e<-0
	For i=0 to n-1 repeat
		If a[i] mod 2=0 then
			Set even[e]<-a[i]
			Set e<-e+1
		else
			Set odd[o]<-a[i]
			Set o<-o+1
		[End of ‘if’]
	[End of ‘for’ loop]
	For i=0 to e-1 repeat
		Print even[i]
	[End of ‘for’ loop]
	For i=0 to o-1 repeat
		Print odd[i]
	[End of ‘for’ loop]
Step 3: Stop.

Code

Complexity: