write a program that take an array s as an argument and add all the odd values and display the sum
Answers
Answered by
3
Using C++
#include<iostream>
using namespace std;
int main()
{
int a, b ,sum=0, i,j;
cout<<"Enter the number of rows and the no. of columns in an array ";
cin>>a>>b;
int ar[a][b];
cout<<"Enter the elements of an array ";
for(i=0;i<a;i++)
{
for(j=0;j<a;j++)
{
cin>>ar[i][j];
}
}
for(i=0;i<a;i++)
{
for(j=0;j<a;j++)
{
if (ar[i][j]%2 != 0)
{
sum= sum+ar[i][j];
}}}
cout<<"The sum of odd numbers in the array is "<<sum;
}
Similar questions