below is my code and part were i am getting an error Write a

below is my code, and part were i am getting an error

Write a C Program to accept N integer numbers and store them in an array. Create 2 new arrays - one to hold the odd integers and one to hold the even integers. Display the contents of both arrays. For example: #include int main() {int NUM = 0; int base[NUM]; int odd[NUM]; int even[NUM]; int i = 0; int j = 0; int k = 0; for (i = 0; i

Solution

#include <stdio.h>

int main(void)
{
   int size,array[20],even[20],odd[20],i,j,k,countj,countk;
   j=k=countj=countk=0;
  
   printf(\"Enter the size of an array that can hold up to 20 integers\");
   scanf(\"%d\",&size); //input size of array
  
   for(i=0;i<size;i++)
   {
       scanf(\"%d\",&array[i]); //input elements of the array
      
   }
  
   for(i=0;i<size;i++)
   {
       if(array[i]%2 == 0) //if element of an array is divided by 2
       {
           even[j] = array[i];   //put it into even array
           j++;
           countj++;
       }
       else
       {
       odd[k] = array[i];   //else put the element in odd array
       k++;
       countk++;
       }
      
   }
   printf(\"\ The elements of the even array\");
   for(i=0;i<countj;i++)
   {
       printf(\"\\t%d\",even[i]);
   }
   printf(\"\ The elements of the odd array\");
   for(i=0;i<countk;i++)
   {
       printf(\"\\t%d\",odd[i]);
   }
  
   return 0;
}


output:

below is my code, and part were i am getting an error Write a C Program to accept N integer numbers and store them in an array. Create 2 new arrays - one to hol

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site