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

12 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

Comment Here