[Solved] C# logic (solution needed in coding) [closed]

The only tricky thing here is a comparison with tolerance, since because of round up errors you can well never meet answer == value condition. The implementation could be double answer = 300.0; double tolerance = 1e-10; while (true) { // based on previous answer we compute next one double value = 0.5 * (answer … Read more

[Solved] Linux C++ new operator incredibly slow [closed]

Given that 98% of the time is spent in that function, I rewrote your “get a number” function: int Ten_To_One_Million_Ten(void) { unsigned Number = (((unsigned)rand() << 5) + (unsigned)rand()%32) % 1000000 + 10; assert(Number >= 10 && Number <= 1000010); return Number; } Now, on my machine, using clang++ (Version 3.7 from about 4 weeks … Read more

[Solved] Sum of an array recursively using one parameter in C

Not Possible Two problems: Where does the array end? In C, arrays are simply blocks of memory and do not have a length property. It is possible to read unpredictable numbers off the end of the array, from other portions of memory. In the posted code, sizeof(*arr) apparently is being used to get the length … Read more

[Solved] PHP script ,MySQL

Change your code from $query = “SELECT COUNT( id ) FROM scores WHERE id = $id;”; $result = mysql_query($query) or die(‘Query failed: ‘ . mysql_error()); to $query = “SELECT COUNT( id ) as `total_ids` FROM scores WHERE id = $id”; $result = mysql_query($query) or die(‘Query failed: ‘ . mysql_error()); after that you need $count = … Read more

[Solved] Error in using rand function [closed]

The solution you look for is rand() % 7 + 4 which will give you results from range [4, 10]. More general, for given min and max to obtain random value from [min, max] you go for rand() % (max – min + 1) + min 1 solved Error in using rand function [closed]

[Solved] Difference between ‘is’ and ‘==’ in C#

They check completely different things. is compares types. == compares values. var isString = “Abc” is String; // => true var equalToString = “Abc” == String; // Error: `string’ is a `type’ but a `variable’ was expected There is one domain where these can both apply, and have different meanings, and that’s in type checking: … Read more

[Solved] Check if the first chars are digits

How can I remove every digit at the beginning? Linq SkipWhile would be one way string result = string.Concat(“1234ABC123”.SkipWhile(char.IsDigit)); // “ABC123” solved Check if the first chars are digits

[Solved] Delegation in C++

First, let’s use a typedef for the function: typedef int agechanger(int); this makes a new type, agechanger, which will be used in code for passing the function instances around. Now, you should give your person class a proper constructor, and properly incapsulate the age field providing a public getter. Then add a method that accepts … Read more