- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a number array and add only odd numbers?
Odd number summation using JavaScript.
Example
<html> <body> <script> var tot = 0; var a = [1,45,78,9,78,40,67,76]; for(var i = 0; i<a.length;i++){ if(a[i]%2 !== 0){ tot += a[i] } } document.write(tot); </script> </body> </html>
Output
122
Explanation: In the above array , since modulus operator is used to find the remainder , when number is divided by 2 if the remainder is 1 then its an odd number and it is programmed to add all odd numbers in an array.
- Related Articles
- Write a number array and using for loop add only even numbers in javascript?
- Returning only odd number from array in JavaScript
- What are composite numbers? Can a composite number be odd? If yes, write the smallest odd composite number.
- Average of odd numbers till a given odd number?
- Finding the only even or the only odd number in a string of space separated numbers in JavaScript
- Adding only odd or even numbers JavaScript
- Write a Golang program to find odd and even numbers using bit operation
- Swift Program to Get Odd and Even Numbers From the Array
- Java program to print odd and even number from a Java array.
- Go through an array and sum only numbers JavaScript
- Even numbers at even index and odd numbers at odd index in C++
- State whether the following statements are True or False:(a) The sum of three odd numbers is even.(b) The sum of two odd numbers and one even number is even.(c) The product of three odd numbers is odd.(d) If an even number is divided by 2, the quotient is always odd.(e) All prime numbers are odd.(f) Prime numbers do not have any factors.(g) Sum of two prime numbers is always even.(h) 2 is the only even prime number.(i) All even numbers are composite numbers.(j) The product of two even numbers is always even.
- Write a program to add two complex numbers using C
- Add two array keeping duplicates only once - JavaScript
- Java program to Print Odd and Even Number from an Array

Advertisements