Write a C Program to accept N integer numbers and store them

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: Enter the size of an array that can hold up to 20 integers: Enter the elements (integers) of the array: 0 1 2 3 4 5 The elements of the odd array are: 1 3 5 The elements of the even array are: 0 2 4

Solution

/* The following is the c code to display the even and odd arrays seperately out of the given array */

#include<stdio.h>
#include<math.h>
int main()
{
   int a[20],b[20],c[20],i,n;
   printf(\"enter the size of array that can hold upto 20 integers\");
   scanf(\"%d\",&n);
   printf(\"enter the a[20] array elements \");
  
   for(i=0;i<n;i++)
   {
       scanf(\"%d\",&a[i]);
   }
  
   printf(\"even elements of the array in the given a[20] array is b[20]: \\t\");
  
   for(i=0;i<n;i++)
   {
       if(a[i]%2==0)
       {
       printf(\"%d\\t\",a[i]);
       }
   }
   printf(\"\ \");
   printf(\"odd elements of the array in the given a[20] array is c[20]: \\t\");
  
   for(i=0;i<n;i++)
   {
       if(a[i]%2==1)
       {
       printf(\"%d\\t\",a[i]);
       }
   }
  
}

 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.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site