Intro to CS MIT -> Lecture 02 - even and odd number

This commit is contained in:
ericdouglas 2015-05-31 14:27:37 -03:00
parent b504a25d24
commit 4a8585e6b8
2 changed files with 55 additions and 2 deletions

View File

@ -3,8 +3,8 @@
## Unit 1
- INTRODUCTION TO 6.00 ✔
- CORE ELEMENTS OF A PROGRAM
- PROBLEM SOLVING
- CORE ELEMENTS OF A PROGRAM
- PROBLEM SOLVING
- MACHINE INTERPRETATION OF A PROGRAM
- OBJECTS IN PYTHON
- RECURSION

View File

@ -0,0 +1,53 @@
//// Create a variable x and assign value 3 to it
//var x = 3;
//
//// Bind x to value 9
//x *= x; // or x = x * x;
//console.log( x );
//// read input data from terminal
//process.stdin.resume();
//
//console.log( 'Enter a number:' );
//process.stdin.setEncoding( 'utf8' );
//
//process.stdin.on( 'data', function( input ) {
//
// console.log( typeof( input ));
// console.log( input );
//
// process.exit();
//
//});
// Verify if a integer number is even or odd.
// If odd, verify if the number is divisible by 3
// read input data from terminal
process.stdin.resume();
console.log( 'Enter a integer:' );
process.stdin.setEncoding( 'utf8' );
process.stdin.on( 'data', function( input ) {
var int = parseInt( input, 10 );
if ( int % 2 === 0 ) {
console.log( 'Even' );
} else {
console.log( 'Odd' );
if ( int % 3 !== 0 ) {
console.log( 'And not divisible by 3' );
}
}
process.exit();
});