0
2.9kviews
Write a program in C to accept an ARRAY A with n elements and separate it into different arrays B and C in such a way that B contains odd numbers and C contains even numbers.

Mumbai University> FE > Sem 2> STRUCTURED PROGRAMMING APPROACH

Marks: 10 M

Year: May 2016

1 Answer
0
195views
#include<stdio.h>
main()
{
int a[10], add[10], even[10];
int i,j=0,k=0,n;
printf(“Enter size of an array”)
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf(“Enter a value”);
scanf(“%d”,&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]%2==0)
{
even[j]=a[i];
j++;
}
else
{
odd[k]=a[i];
k++;
}
}

printf(“Even Array:\n”);
for(i=0;i<j;i++)
{
printf(“%d\n”,even[i]);
}
printf(“Odd Array:\n”);
for(i=0;i<k;i++)
{
printf(“%d\n”,odd[i]);
}
}

Output:
Enter a value:3
Enter a value:2
Enter a value:4
Enter a value:2
Enter a value:5
Enter a value:7
Enter a value:8
Even Array:
2
4
2
8
Odd  Array:
3
5
7
Please log in to add an answer.