Sunday, December 7, 2014

Write a program of function to Sum of all even elements from an Array. The initial value of the array must take from main ( ) as input

#include <iostream>
    using namespace std;

    class evensum
    {
    public:
        void setvalue(int v)
        {
            value =v;
        }
        protected: int value;

    };

class mysum: public evensum
{
public:
    void getsum()
    {
    int temperature,i,a[100],sum=0;
    temperature=value;
    cout<<"Enter "<<temperature<< " values:  ";
    for(i=0;i<temperature; i++)
    {
    cin>>a[i];
    }
    for (i=0;i<temperature;i++)
    {
    if (a[i]%2==0)
    {
    sum+=a[i];
    }
    }
    cout<<"Sum of even values is : "<<sum<<endl;
    }
};
    int  main()
    {
    findsum xy;
    int v;
    cout<<"Enter size of the array: ";
    cin>>v;
    xy.setvalue(v);
    xy.getsum();
    return 0;
    }

No comments:

Post a Comment