Wednesday, 6 March 2013

Program to split array into another array


By on 05:02

Split Program in C language:-

Q)Write a program to create array and split the array into two parts i.e. even and odd.


Note:-You can also create this program in c++(c plus plus),java,c#(c sharp) languages with the same logic.



void main() 
{
int a[20],e[20],o[20],i,j,k,n;
clrscr();
printf("Enter array limit");
scanf("%d",&n);
printf("Enter array element");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
j=k=0;
for(i=0;i<n;i++)
{
if(a[i]%2==0)
{
e[j]=a[i];
j++;
}
else
{
o[k]=a[i];
k++;
}
}
printf("Even Array");
for(i=0;i<j;i++)
printf("%d",e[i]);
printf("Odd Array");
for(i=0;i<k;i++)
printf("%d",o[i]);
getch();
}


If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...