27.11.14

Excercise-17 : Function Progamming


Write a program using function to Sum of all Odd numbers from an Array. Use function prototype and parameter

16 comments:

  1. #include
    using namespace std;
    int arraysum(int a[],int len);
    main()
    {
    int len,j;
    cout<<"the array size is:"<>len;
    int a[len];
    cout<<"\nyour values:";
    for(j=0;j>a[j];

    arraysum(a,len);
    }
    int arraysum(int b[],int n)
    {
    int i,sum=0;
    for(i=0;i<n;i++)
    {
    if(b[i]%2==1)
    {
    cout<<"Odd: "<<b[i]<<endl;
    sum+=b[i];
    }
    }
    cout<<sum;
    }

    ReplyDelete
  2. Dear Sir, Please visit below blog:
    http://itlearn24.blogspot.com/2014/11/write-program-using-function-to-sum-of.html

    ReplyDelete
  3. #include
    using namespace std;


    void even_odd(int p)
    {
    if(p%2==0)
    cout<<"Enter number is Even";
    else
    cout<<" nter number is Odd";
    }

    int main()
    {
    int n;
    cout<<"Enter number to check Even or odd ";
    cin>>p;
    even_odd(p);
    return 0;
    }

    ReplyDelete
  4. #include
    using namespace std;

    int getsum( int j)
    {
    int a[100],sum=0;
    cout<<"Enter "<>a[i];
    }
    for (int i=0;i>j;
    cout<<endl<<"Sum of odd numbers is : "<<getsum(j)<<endl;
    return 0;
    }

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. #include
    using namespace std;

    class F
    {
    public:
    void setnum(int p)
    {
    number = p;
    }
    protected: int number;
    };
    class findfact: public Factorial
    {
    public:
    int fact=1;
    void getfact()
    {
    for(int i = 1; i <= number; i++)
    {
    fact *= i;
    }
    cout<<"The Factorial value for the number is "<>p;
    facts.setnum(n);
    facts.getfact();
    return 0;
    }

    ReplyDelete
  7. #include
    #include
    using namespace std;

    int character (string n)
    {
    int charnum=n.size();
    for(char i=0; i<n.size(); i++)
    {
    if(n.at(i)== ' ')
    {
    charnum--;
    }
    if(n.at(i)== '.')
    {
    charnum--;
    }
    }
    cout<<endl<<"Enter string has "<<charnum <<" Characters:"<<endl;
    }


    int main()
    {
    string n;
    char i;
    cout<<"Please type in a string: " ;
    getline(cin,n);
    character(n);
    return 0;
    }

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. #include
    using namespace std;

    int getsum( int b)
    {
    int a[100],sum=0;
    cout<<"Enter "<>a[i];
    }
    for (int i=0;i>b;
    cout<<endl<<"Sum of odd numbers is : "<<getsum(b)<<endl;
    return 0;
    }

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Name : Sumsunnahar Nawa
    ID : 201710090
    Batch:54th
    https://drive.google.com/open?id=1RL2c4X9eIC1X7WvalZM0o8Z6XaDx46s3

    ReplyDelete
  12. ID #201611036
    Link--> https://drive.google.com/open?id=1V0EMYqUSVzD2-6JQbKKjZh_8xDjSyz_X

    ReplyDelete
  13. MD Shipon Hossan
    ID:201810009
    https://drive.google.com/open?id=1DfgN3Mj4Ek23b0-fHvi_uPTTW8J0a_ME

    ReplyDelete
  14. ID # 201610288
    Semester : Summer 2018
    ----------------------
    Write any program to call a member function which will be cause of a different function to be executed depending on the types of object that invokes the function
    ---------------------
    #include
    #include //cmath file is included
    using namespace std;

    class areaCal{
    public:
    area(double x, double y){
    calculate(x,y);
    cout << "The area of the rectangle is : " << _a << endl;
    }
    area(double a, double b, double c){
    calculate(a, b, c);
    cout << "The area of the triangle is : " << _a << endl;
    }
    private:
    double _a;

    calculate(double x, double y){
    _a = x*y;
    }

    calculate(double a, double b, double c){
    double s;
    s = (a+b+c)/2;
    _a = sqrt(s*(s-a)*(s-b)*(s-c));
    }


    };

    int main(){

    double a, b, c;
    cout << "Input first side of the triangle : ";
    cin >> a;
    cout << "Input first side of the triangle : ";
    cin >> b;
    cout << "Input first side of the triangle : ";
    cin >> c;

    areaCal tri;
    tri.area(a,b,c);

    cout << "-------------------------------" << endl;
    cout << "-------------------------------" << endl;

    double x, y;
    cout << "Input length of the rectangle : ";
    cin >> x;
    cout << "Input width of the rectangle : ";
    cin >> y;

    areaCal rect;
    rect.area(x,y);
    }

    ReplyDelete

Comment Here