C Program To Put Even And Odd Elements Of Array Into Two Separate Arrays

C program to put even and odd elements or numbers of the array into two separate arrays; Through this tutorial, we will learn how to put even and odd elements or numbers of an array into two separate arrays using standard method and function in c programs.

Programs To Put Even And Odd Elements Of Array Into Two Separate Arrays in C

Let’s use the following programs to put even and odd elements or numbers of an array into two separate arrays using standard method and function in c:

  • C Program To Put Even And Odd Elements Of Array Into Two Separate Arrays using Standard Method
  • C Program To Put Even And Odd Elements Of Array Into Two Separate Arrays using Function

C Program To Put Even And Odd Elements Of Array Into Two Separate Arrays using Standard Method

 #include <stdio.h>

print(int *a,int n)
 {
    int i;



    for(i=0; i<n; i++)
    {

        	printf("%d  ",a[i]);


    }

 }


int main()
{
    int a[10000],b[10000],c[20000],i,j,k,n1,n2,n ;

    printf("Enter size of the  array : ");
    scanf("%d", &n);
    printf("Enter elements in array : ");
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
     printf("\n original array  \n");

    print(a,n);
    j=k=0;
    for(i=0; i<n; i++)
    {
        if(a[i]%2==0)
          b[j++]=a[i];
        else
          c[k++]=a[i];

    }

    printf(" \n even array \n");

    print(b,j);
    printf(" \n odd array \n");

    print(c,k);





    return 0;
} 

The output of the above c program; as follows:

Enter size of the  array : 10
Enter elements in array : 1 2 3 4 5 6 7 8 9 10
original array
1  2  3  4  5  6  7  8  9  10
 even array
2  4  6  8  10
 odd array
1  3  5  7  9  

C Program To Put Even And Odd Elements Of Array Into Two Separate Arrays using Function

#include <stdio.h>

print(int *a,int n)
 {
    int i;



    for(i=0; i<n; i++)
    {

        	printf("%d  ",a[i]);


    }

 }
function(int *a,int *b,int *c,int n)
{
    int i,j,k,temp;

       j=k=0;
    for(i=0; i<n; i++)
    {
        if(a[i]%2==0)
          b[j++]=a[i];
        else
          c[k++]=a[i];

    }

   printf("\n original array  \n");

    print(a,n);


    printf(" \n even array \n");

    print(b,j);
    printf(" \n odd array \n");

    print(c,k);


 }



int main()
{
    int a[10000],b[10000],c[20000],i,j,k,n1,n2,n ;

    printf("Enter size of the  array : ");

	scanf("%d", &n);

	printf("Enter elements in array : ");

	for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }


    function(a,b,c,n);

    return 0;
}

The output of the above c program; as follows:

Enter size of the  array : 10
Enter elements in array : 1 2 3 4 5 6 3 4 7 4
original array
1  2  3  4  5  6  3  4  7  4
 even array
2  4  6  4  4
 odd array
1  3  5  3  7  

Recommended C Programs

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *