Friday, 27 January 2012

Arrays in the form of different Parameters



#include<iostream>
using namespace std;
int show_array(int arr[],int size,int *ptreven,int *ptrodd)
{ 
 for(int j=0;j<size;j++)
 {
  if(arr[j]%2==0)
   *ptreven=*ptreven+arr[j];
  else
   *ptrodd=*ptrodd+arr[j];
 }
 return (*ptreven+*ptrodd);
}

int main()
{
 //variables
 int const SIZE=10;
 int arr[SIZE];
 int sumeven=0,sumodd=0,totalsum=0; 
 
 //Calling
 for(int i=0;i<SIZE;i++)
 {
  cout<<"Enter number At "<<i<<" index :";
  cin>>arr[i];
 }
 totalsum=show_array(arr,SIZE,&sumeven,&sumodd);
 cout<<"Sum of even elements in array :"<<sumeven<<endl;
 cout<<"Sum of odd elements in array :"<<sumodd<<endl;
 cout<<"Sum of All elements in array :"<<totalsum<<endl;
 return 0;
}

No comments:

Post a Comment