Answer the question
In order to leave comments, you need to log in
Turbo Pascal How to count the numbers in the ones place?
Hello!
They turned to me with a request to evaluate the solution of the problem for which two people were slapped. Everything seems to be correct, but why the deuce is not clear .. or maybe I don’t see something?
Task:
Calculate the number of numbers in the range from 11607 to 55176 which have the number 1 or the number 8 in the ones place
Solution:
Program urok;
var i, kol :integer;
begin
kol:=0;
for i:= 11607 to 55176 do if ( ((i mod 100) div 1 = 1) or((i mod 100) div 1 = 8)) then begin kol:=kol+1; writeln('Есть подходящее число: ',i, '. Текущее количество чисел: ', kol); end;
writeln(' Общее количество чисел: ', kol);
end.
Answer the question
In order to leave comments, you need to log in
Two ? There would be a stake! A masterpiece like (i mod 100) div 1 = 8 is just beautiful :)
if( i mod 10 ) = 8 then
// ( i mod 10 ) = get the modulo 10 which is the last digit of i
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question