-1

How can I use mod, or div, to detect if a given positive integer is a two-tigit one? For instance, if the given number is 23 it will shows a message saying 'Two-digit number' But if the number is 230 it will show 'Not a two-digit number' NOTE: I HAVE TO USE ONLY SIMPLE COMMANDS - NO FUNCTIONS

Let's say the given number is 77 I tried doing 77 mod 10 But it didn't work for all the number What should I do?

  • 1
    `InRange(x, 10, 99)` note that I'm not sure how or if you want to handle negative numbers – David Heffernan Dec 08 '22 at 17:21
  • 1
    If anybody suggests converting to a string I will cry – David Heffernan Dec 08 '22 at 17:21
  • 1
    Without function call, `if (x < 100) and (x >= 10)` or `if ((x div 100) < 10) and ((x div 10) > 0)` – LU RD Dec 08 '22 at 17:29
  • why would you perform a divide @LURD or indeed two – David Heffernan Dec 08 '22 at 17:37
  • I know that a integer division is not the fastest thing on earth. The question asks for a solution using `mod` or `div` though. And not a function call. – LU RD Dec 08 '22 at 17:40
  • If you can't call a function then yes it's back to comparison operators – David Heffernan Dec 08 '22 at 17:40
  • 1
    This is your [2nd question with the "no functions" requirement](https://stackoverflow.com/q/74657922/4299358) and it also sounds like a homework task. You will not learn if you outsource the assignments. – AmigoJack Dec 11 '22 at 23:52
  • It's not homework, I am just really familiar with other languages and before going deep into pascal, I need to learn the basics to understand it better. It's not that nowadays a lot of people use pascal – programm.ing Dec 15 '22 at 13:27

2 Answers2

2

Given the integer is a positive number and not using a function call :

if  (x < 100) and (x >= 10) then ... // 2 - digit postive number 
LU RD
  • 34,438
  • 5
  • 88
  • 296
1

Using just div:

if ((x div 100) < 1) and ((x div 10) >= 1) then
  ...
Chris
  • 26,361
  • 5
  • 21
  • 42