Question:
How many three digit numbers are there such that the hundreds digit is less than or equal to the tens digit and the ones digit is less than or equal to the tens digit?
Answer: 330
Solved using the script below:
console.log("***************************************");
function threeDigitNum(a,b,c){
return a*100 + b*10 + c*1;
}
var count=0;
for(var i=0; i<=9; i++){
for(var j=0; j<=9; j++){
for(var k=0; k<=9; k++){
var temp = threeDigitNum(i,j,k);
if(i<=j && k<=j && temp>=100){
console.log("i: "+i+" j: "+j+" k: "+k+" num:"+temp);
count++;
}
}
}
}
console.log("count is "+count);
No comments:
Post a Comment