
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Add Only Odd Numbers from a Number Array
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.
Advertisements