Nov 30, 2014

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

#include <iostream>
using namespace std;

int getsum( int n)
    {
    int a[100],sum=0;
    cout<<"Enter "<<n<< " numbers:  ";
    for(int i=0;i<n; i++)
    {
    cin>>a[i];
    }
    for (int i=0;i<n;i++)
    {
    if (a[i]%2!=0)
    {
    sum+=a[i];
    }
    }
    return sum;
    }


    int  main()
    {
    int n;
    cout<<"Enter size of array: ";
    cin>>n;
    cout<<endl<<"Sum of odd numbers is : "<<getsum(n)<<endl;
    return 0;
    }

No comments:

Create a Diamond in C++

 #include<iostream> using namespace std; int main() { int i, j, k,r; cout<<"Enter the row of diamond   "; cin>>r...