Respuesta :
Answer:
Following are the code to this question:
#include <iostream>//defining header file
using namespace std;
int main()//defining main method
{
int x[]={2,3,4,6,7,8,9,1,11,12};//defining 1-D array and assign value
int i,sum=0;//defining integer variable
for(i=0;i<10;i++)//defining loop for count value
{
if(x[i]%2==1)//defining if block to check odd value
{
sum=sum+x[i];//add value in sum variable
}
}
cout<<sum;//print sum
return 0;
}
Output:
31
Explanation:
In the above-given program, an integer array "x" is declared that holds some integer values, and in the next line two integer variable "i and sum" is defined which is used to calculate the value.
In the next line, a for loop is declared, that counts all array value, and it uses the if block to check the odd value and add all the value into the sum variable.
The code is in Java.
It uses for loop, if-else structure, and mod to calculate the sum of odd numbers in a list.
Comments are used to explain each line of code.
You may see the output in the attachment.
//Main.java
import java.util.*;
public class Main
{
public static void main(String[] args) {
//create a list with some numbers
List<Integer> lotsOfNumbers = Arrays.asList(7, 20, 1002, 55, 406, 99);
//initialize the sum as 0
int sumOfOdds = 0;
//create a for each loop to iterate over the lotsOfNumbers list
//check each number, if it is odd or not using the mod
//if it is odd, add the number to the sum (cumulative sum)
for (int number : lotsOfNumbers){
if(number % 2 == 1)
sumOfOdds += number;
}
//print the sum
System.out.println("The sum of odd numbers: " + sumOfOdds);
}
}
You may check out another question at:
https://brainly.com/question/24914609
