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

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

  • 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

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of 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 from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published.