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 7 years ago.
Improve this question
I never really get it, but what does the modulus operator (%) do.
And when would you want to use it in a mathematical context? By the way, I
just want to know what it does, not how it works.
It calculates the remainder of a division operation.
5 / 2 == 2 // whole part of the division
5 % 2 == 1 // remainder
In other words you could reconstruct the original number by
2 * 2 + 1 == 5
| | ^ remainder
| ^ whole part
^ divisor
Related
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 3 years ago.
Improve this question
How does this work?
int a=5<=5;
cout<<a; // output : 1
Who can explain why output is 1?
That's because
<= has higher priority than = so it is calculated first.
5 <= 5 returns a boolean, which is true.
It is converted into an integer, which is 1.
then 1 is assigned to a.
so a equals 1 now.
5<=5 is true which, when converted to an integer is 1.
You assign this value to a which then holds the value 1. Which you then output.
You may want to read https://en.cppreference.com/w/cpp/language/operator_precedence
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’m very new in C++ and I need your help. I want to use the input value as a mathematical function then print the result.
What i need is:
When user input: 2 +1 and hit Enter then output (cout>>)
should be your result is: 3 (the sum of 2 + 1)
The mathematical symbol could be + or * or / or -.
Could you please help me with some example?
Thanks in advance!
Search for "Reverse Polish notation" and implementation in 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 6 years ago.
Improve this question
Is it possible to find the highest number in a list given any arbitrary number of items in the list? If so, please let me know how it can be done. I'm fairly new to Scheme.
You can use max function. Since your input is list of numbers, you can use apply function.
> (max 1 2 3 4)
4
> (apply max '(1 2 3 4 5 6 100 89 23))
100
>
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 9 years ago.
Improve this question
I have a task to create a mathematical formula in c++, input some variables and get a result.
The problem is that I don't know how to represent and calculate the following:
sin(3 mod 180)
I`m aware that mod operator finds the remainder of a division. I can figure that out for 180 mod 3, but for 3 mod 180.
C++ and standard C library provides methods for most arithmetic operations std::sin being one of them. You can do mod using modulo operator.
I.e. std::sin(3 % 180)
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 9 years ago.
Improve this question
I'm creating a program that will output whether a number is prime or not. although, I'm trying to make it a little more complicated. I created a vector which I now want to store every prime number up to and including the number input by the user.
And then for the number input by the user (i.e. if the user types 13) will return true for the function hence it is a prime number. Here are some examples:
**U
primechecker() : plist(2) {;}
bool operator()(int);
3 5 7
then 3 5 6 7 7
The reason your vector is starting with two zeros is because you are initializing it with two elements of the default constructor:
primechecker() : plist(2)
Check out the documentation of std::vector (you are using the 'fill constructor')