“Modulus” Kode Jawaban

Modulus JS

//We are trying to find a table for my speed dating group to sit at, that is the most economical for the restaurant. How many options do I have?

const tableNumbers = [5, 14, 7, 10, 20, 11, 12, 15, 3]

for (let i =0; i < tableNumbers.length; i++) {
  //if the tableNumbers length can be divided by 2 (%) = and leavs a remainder of 0 
    if (tableNumbers[i] % 2 === 0) {
        console.log(tableNumbers[i])
    }
}
Thoughtful Teira

Modulus

C++ provides the modulus operator, %, that yields the remainder after integer division. 
The modulus operator can be used only with integer operands. The expression x % y yields the remainder after x is divided by y. 
Thus, 7 % 4 yields 3 and 17 % 5 yields 2.

Example:

#include <iostream>
using namespace std;

int main() 
{
	cout << 11%3; // Prints 2
    
    return 0;
}
Condemned Cobra

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya