generating random int input from -100 to 100 [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to generate random numbers between -100 to 100 however i am not sure which of these will generate the right numbers
rand()%201 - 100; or rand()%200 - 100;

The first one, rand()%201 - 100.
The second one will never hit positive 100, as rand()%200 will never be 200.

Related

writing c++ program "fraction of double" [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I wanna write a c++ program that read a double value and after reading it print only the fraction of that number, for example if the input was 14.25 then the output must be 0.25
should include iomanip to it?
One approach would be to
Round the number down to the nearest integer - you can use the floor() function (http://www.cplusplus.com/reference/cmath/floor/)
Subtract that integer from the original number to get the result

How do you transform a number to its sign? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How do you transform a number to its sign (for example -50 = -1, 50 = 1) without using the if statement, just mathematical operations?
Why not just do this
int sign = i<=0 ? -1 : 1;

how to generrate array of integers (exact same every time)? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am trying to generate array of integers within specific limit using random number generator but I want exact same array every time .
Seed your generator with the same seed value every time and it will produce the same sequence of numbers (true for most generators).

Regular expression to match n digit before precision and only two digit after precision [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Eg: only allow
< n digit>.<2 digit>
[0-9]{0,}\.[0-9]{2} if you need exactly 2 digit after the dot
[0-9]{0,}(\.[0-9]{1,2}){0,1} if precision can be empty

displaying sequence of numbers [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to understand the pattern of these sequence of numbers and write c++ code using one of loop structures.the numbers are:
1, 2, 5, 14, 41, ...
I want the code to display these numbers.Can somebody help me with this?Thank you in advance.
You can search for such sequences on your favorite web search engine and you'll usually end up on OEIS.org. In this case, here: https://oeis.org/A007051
Your equation is (3^n + 1)/2.