-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathput_odd_even_array.c
More file actions
128 lines (101 loc) · 2.56 KB
/
put_odd_even_array.c
File metadata and controls
128 lines (101 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
* C program to separate even and odd array elements in two separate array
*/
#include <stdio.h>
#define MAX_SIZE 1000 // Maximum size of the array
/* Function to print array */
void printArray(int arr[], int len);
int main()
{
int arr[MAX_SIZE];
int even[MAX_SIZE], odd[MAX_SIZE];
int evenCount, oddCount;
int i, size;
/* Input size of the array */
printf("Enter size of the array: ");
scanf("%d", &size);
/* Input elements in array */
printf("Enter elements in the array: ");
for(i=0; i<size; i++)
{
scanf("%d", &arr[i]);
}
evenCount = 0;
oddCount = 0;
for(i=0; i<size; i++)
{
// If arr[i] is odd
if(arr[i] & 1)
{
odd[oddCount] = arr[i];
oddCount++;
}
else
{
even[evenCount] = arr[i];
evenCount++;
}
}
printf("\nElements of even array: \n");
printArray(even, evenCount);
printf("\nElements of odd array: \n");
printArray(odd, oddCount);
return 0;
}
/**
* Print the entire integer array
* @arr Integer array to be displayed or printed on screen
* @len Length of the array
*/
void printArray(int arr[], int len)
{
int i;
printf("Elements in the array: ");
for(i=0; i<len; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
}
// /**
// * C program to separate even and odd array elements in two separate array
// */
// #include <stdio.h>
// int main()
// {
// int arr[100], oddarr[100], evenarr[100];
// int size, count = 0;
// int evenCount, oddCount;
// printf("Enter the size of array : ");
// scanf("%d", &size);
// for (int i = 0; i < size; i++)
// {
// printf("Enter element of array at %d : ", i);
// scanf("%d", &arr[i]);
// }
// evenCount = 0;
// oddCount = 0;
// for (int i = 0; i < size; i++)
// {
// if (arr[i] % 2 == 0)
// {
// evenarr[evenCount] = arr[i];
// evenCount++;
// }
// else
// {
// oddarr[oddCount] = arr[i];
// oddCount++;
// }
// }
// // for printing array
// for (int i = 0; i < evenCount; i++)
// {
// printf("%d ", evenarr[i]);
// }
// for (int i = 0; i < oddCount; i++)
// {
// printf("%d ", oddarr[i]);
// }
// return 0;
// }