

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- Write a number array and using for loop add only even numbers in javascript?
- Returning only odd number from array in JavaScript
- Average of odd numbers till a given odd number?
- Adding only odd or even numbers JavaScript
- Finding the only even or the only odd number in a string of space separated numbers in JavaScript
- Write a Golang program to find odd and even numbers using bit operation
- Write a program to add two complex numbers using C
- Go through an array and sum only numbers JavaScript
- How to write Regex for numbers only in C#?
- Even numbers at even index and odd numbers at odd index in C++
- Java program to print odd and even number from a Java array.
- Add two array keeping duplicates only once - JavaScript
- Java program to Print Odd and Even Number from an Array
- How to find the Odd and Even numbers in an Array in java?
- Recursion in array to find odd numbers and push to new variable JavaScript
Advertisements