What do you have so far to test with? A few vague images on imgur is not really a problem description.Write a program in PASCAL that shows on the screen the last digit of a whole number.
Show us the code you have written so far.What do you have so far to test with? A few vague images on imgur is not really a problem description.Write a program in PASCAL that shows on the screen the last digit of a whole number.
That's an algorithm we use subconciously everyday, and we don't even know it
That's an algorithm we use subconciously everyday, and we don't even know it
Strange reasoning. So only algorithms in every day practice are allowed in programming?
I wonder what would happen if you apply that to physics, how do you determine the number of atoms in a gram of matter? You count them one by one, because that is what you do in every day practice! :D
Hands up, who in such a case uses the Modulo-way, and who uses the "String-Operations"-way....
If i do online-banking, and the bank asks me for the last four digits of my credit-card-number, i don't do math. I do String-Operations, "writeln(Right(CreditCardNumber.ToString, 4));"
This is homework-assignment, and he doesn't even know what he'd be doing in real-life to solve the problem.
Hands up, who in such a case uses the Modulo-way, and who uses the "String-Operations"-way....
If i do online-banking, and the bank asks me for the last four digits of my credit-card-number, i don't do math. I do String-Operations, "writeln(Right(CreditCardNumber.ToString, 4));"
(don't take all this to serious, but I do recommend the OP to consider both ways)
That step to modeling as string operations is just as much as an IT specific indoctrination as the math approach is.
Both are about isolating digits based on position. One uses the fact that a position more to the left means 10 times the value, and one simply counts positions.
In the past this was considered Basic diseases, i.e. too much exposure to Basic and/or scripting languages.QuoteThis is homework-assignment, and he doesn't even know what he'd be doing in real-life to solve the problem.
Homework is about learning. And, if you think about it, the string way involves as many divisions as there are digits, and the math way exactly one.
...but you're forgetting the main purpose of Computer-Programming:
Replicating Real-Life-Processes to be calculated by a Computer.
My 2€-cents.
writeln(i mod 10);
... writeln(ReverseString(MyNumber.ToString)[1]); ...