Chapter:

Arrays-

Write a program in C to separate odd and even integers in separate arrays.

Write a program in C to separate odd and even integers in separate arrays.

#include <stdio.h>
void main()
 {
       int arr1[10], arr2[10], arr3[10];
       int i,j=0,k=0,n;
       printf("\n\nSeparate odd and even integers in separate arrays:\n");
       printf("Input the number of elements to be stored in the array :");
       fflush(stdout);
       scanf("%d",&n);
       printf("Input %d elements in the array :\n",n);
       for(i=0;i<n;i++)
            {
	         printf("element - %d : ",i);
	         fflush(stdout);
   	      scanf("%d",&arr1[i]);
	       }
    for(i=0;i<n;i++)
    {
   	if (arr1[i]%2 == 0)
   	{
	      arr2[j] = arr1[i];
	      j++;
   	}
 	else
 	{
	   arr3[k] = arr1[i];
	   k++;
 	}
   }
 printf("\nThe Even elements are : \n");
    for(i=0;i<j;i++)
    {
	   printf("%d ",arr2[i]);
    }
    pr....
Show More

All Chapters

View all Chapter and number of question available From each chapter from C-programming-