Help with Visual G

Asked

Viewed 57 times

1

I’m having a problem in Visual G. It’s a college exercise (ADS - 1st Semester).

I need to create an even or odd number identifier, however, without using MOD, division or multiplication, only sum and subtraction and only with commands Escreva/Escreval, leia, se, entao and senao. I’ve tried it many ways but so far it hasn’t worked.

Could someone help me? Follow my code:

Var

 num:inteiro

 Inicio

  escreva("Olá usuário, digite um número: ")
    leia (num)

  se num +2 = 2,4,6,8,0 entao 
  escreva("Este número é par!")

  senao
  escreva("Este número é impar!") 

   fimse  
Fimalgoritmo
  • 1

    Hello @Azerus, welcome to Sopt. Put the code you already have, and have tried, so we can help you better.

  • 1

    "however, without using MOD, Division or Multiplication" very difficult without using this, I think you first need to solve the math problem before thinking about the algorithm, because according to the website brasilescola.uol.com.br: "The pairs are those ending in 0, 2, 4, 6 or 8. The odd ones are those that are not even and are finished in 1, 3, 5, 7 or 9.", different than everyone thinks that, even number is the one who divide by 2 does not bring rest, which is a truth, but...

  • looking at that other definition, you need to take the number to see its last digit, think about it...

  • @Joãomartins This is the code I’m using: Var num:integer Home type("Hello user, type a number: ") read (num) if a +2 = 2,4,6,8,0 then type("This number is even!" ) senao type("This

  • @Azerus click the button editar to edit your question and enter the code in it providing more details of the problem.

  • @clear cat, ready!

  • @Azerus You want to create an algorithm that identifies the even or odd number without using a mathematical formula?

  • @exact cat, only with sum and subtraction.

  • @Azerus then you are using mathematics, whether you intend to use sum or subtraction.

  • @cat yes, just sum and subtraction...

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.