Wednesday 15 January 2014

Extracting even numbers from an array and storing them in another array

#include<iostream.h>
#include<conio.h>
void main()
{
int src[20],des[20];
int n;
   clrscr();
cout<<"Enter the no.of elements in source array..";
cin>>n;
for(int i=0,j=0;i<n;i++)
{
cout<<"enter value:"<<i+1<<"\n";
cin>>src[i];
if(src[i]%2==0)
{
des[j++]=src[i];
}
}
cout<<"Destination array elements are..:";
for(i=0;i<j;i++)
{
cout<<"\n"<<des[i];
}
getch();
}

No comments:

Post a Comment