My problem: Input the string1 and split string1 into string a containing even number and string b containing odd number.
ex: array: 4 3 1 2 6 8
array a: 2 4 6 8 array b: 1 3
when i ran this code, it had problem. Can you help me find the mistakes?
#include<stdio.h>
#include<conio.h>
#include<string.h>
void problem(int a[100], int n);
void bubblesort(int a[100], int n);
void print_array(int a[100], int n);
int main()
{
int b[100],c[100],evenlen=0,oddlen=0,a[100], n;
printf("Input n: "); scanf_s("%d", &n);
printf("Input array: ");
for (int i = 0; i < n; i++)
{
scanf_s("%d", &a[i]);
}
for (int i = 0; i < n; i++)
{
if ((a[i] % 2) == 0)
{
a[i] = b[evenlen];
evenlen++;
}
else
{
a[i] = c[oddlen];
oddlen++;
}
}
bubblesort(b, evenlen);
bubblesort(c, oddlen);
printf("The even array : "); print_array(b, evenlen);
printf("\nThe odd array : "); print_array(c, oddlen);
_getch();
return 0;
}
void bubblesort(int a[100], int n)
{
int hold;
for (int pass = 0; pass < n;pass++)
for (int i = 0; i < n - 1; i++)
{
if (a[i]>a[i + 1])
{
hold = a[i];
a[i] = a[i + 1];
a[i + 1] = hold;
}
}
}
void print_array(int a[100], int n)
{
for (int i = 0; i < n; i++)
printf("%d ", a[i]);
}
when i ran this code, it had problem...what problem?bubblesort()does not sort your array. Google for bubble sort algorithm.