Login Register






Tutorial Something Interesting filter_list
Author
Message
Something Interesting #1
This is a mathematical way to count how many characters there are in a given input which is an integer.

Code:
Function intCount(ByVal input As Integer) Dim count As Integer = 1 Dim power As Integer = 10 While power <= input count += 1 power *= 10 End While Return count End Function Sub Main() Console.WriteLine(intCount(Console.ReadLine)) Console.ReadLine() End Sub


What this is doing is incrementing the starting counter of 1 each time by 1 that the power is able to be multiplied by 10, but still be lower than the input of the function.
[Image: GiXvY27.png]

Reply

RE: Something Interesting #2
HOLY SHIT YOU'RE BACK!

Welcome back!

Totally off topic but sorry.
[Image: tenor.gif]

🍫  🍬 🎀

Reply

RE: Something Interesting #3
Haha, no problem man. Hit me up on Skype @Sapientia.coder if you want.
[Image: GiXvY27.png]

Reply

RE: Something Interesting #4
(09-08-2015, 02:18 AM)Sapientia Wrote: This is a mathematical way to count how many characters there are in a given input which is an integer.

Code:
Function intCount(ByVal input As Integer) Dim count As Integer = 1 Dim power As Integer = 10 While power <= input count += 1 power *= 10 End While Return count End Function Sub Main() Console.WriteLine(intCount(Console.ReadLine)) Console.ReadLine() End Sub


What this is doing is incrementing the starting counter of 1 each time by 1 that the power is able to be multiplied by 10, but still be lower than the input of the function.

There are no "characters" in an integer... :\ You mean digits?

Additionally you can use logarithms for this instead.
Code:
floor(log10(abs(x))) + 1

Here's my C macro as a proof of concept:
Code:
#define digits(x) (floor(log10(abs(x))) + 1)

Code:
#include <iostream> #include <cmath> #define digits(x) (floor(log10(abs(x))) + 1) int main() { std::cout << digits(23480) << '\n'; // 5 }

Reply

RE: Something Interesting #5
(09-13-2015, 06:33 AM)0xDEAD10CC Wrote: There are no "characters" in an integer... :\ You mean digits?

Additionally you can use logarithms for this instead.
Code:
floor(log10(abs(x))) + 1

Here's my C macro as a proof of concept:
Code:
#define digits(x) (floor(log10(abs(x))) + 1)

Code:
#include <iostream> #include <cmath> #define digits(x) (floor(log10(abs(x))) + 1) int main() { std::cout << digits(23480) << '\n'; // 5 }


Yeah, didn't mean to say character.
[Image: GiXvY27.png]

Reply

RE: Something Interesting #6
Hello

I am a new Edu

You can helper work a new topic

I worked the subject and I want to transfer to the Department of vb.net

https://www.sinister.ly/usercp.php?action=drafts

Reply