C Program to accept N integer number and store them in an array AR. The odd elements in the AR are copied into OAR and other elements are copied into EAR. Display the contents of OAR and EAR

by Nideesh C on April 12, 2011 · 0 comments

in C Programming




/* Program to accept N integer number and store them in an array AR. The odd elements in the AR are copied into OAR and other elements are copied into EAR. Display the contents of OAR and EAR */

#include <stdio.h>
void main()
{
long int ARR[10], OAR[10], EAR[10];
int i,j=0,k=0,n;

printf(“Enter the size of array AR\n”);
scanf(“%d”,&n);

printf(“Enter the elements of the array\n”);
for(i=0;i<n;i++)
{
scanf(“%ld”,&ARR[i]);
fflush(stdin);
}
/*Copy odd and even elements in to their respective arrays*/
for(i=0;i<n;i++)
{
if (ARR[i]%2 == 0)
{
EAR[j] = ARR[i];
j++;
}
else
{
OAR[k] = ARR[i];
k++;
}
}

printf(“The elements of OAR are\n”);
for(i=0;i<j;i++)
{
printf(“%ld\n”,OAR[i]);
}

printf(“The elements of EAR are\n”);
for(i=0;i<k;i++)
{
printf(“%ld\n”, EAR[i]);
}
}    /*End of main()*/
/*————————————-
Output
Enter the size of array AR
6
Enter the elements of the array
12
345
678
899
900
111
The elements of OAR are
345
899
111
The elements of EAR are
12
678
900
—————————————*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to read N integers and store them in an array A, and so find the sum of all these elements using pointer. Output the given array and and the computed sum with suitable heading
  2. C program to sort given N elements using SELECTION sort method using functions a) To find maximum of elements b) To swap two elements
  3. C program to read a matrix A (MxN) and to find the following using functions a) Sum of the elements of each row b) Sum of the elements of each column c) Find the sum of all the elements of the matrix Output the computed results with suitable headings
  4. C program to accept N numbers sorted in ascending order and to search for a given number using binary search. Report success or failure in the form of suitable messages
  5. C program to input N numbers (integers or reals) and store them in an array. Conduct a linear search for a given key number and report success or failure in the form of a suitable message

Leave a Comment

Previous post:

Next post: