How to calculate modulus? [closed] - c++

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)

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 to write this mathematical formula in C++? [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
I have a simple formula and I want to use it in C++ application.
Not sure how to rewrite in C++.
logn(5, abs((a*b - d*c) / (tan(c) + sin(d))))
where logn is:
double logn(double base, double x) {
return log(x) / log(base);
}
and the header cmath is included for the other functions.
You can do this, be careful with libs, namespaces, and radian arguments
z = a*b - d*c;
s = tan(c) + sin(d);
num = abs(z/s);
log(num)/log(5);
http://www.cplusplus.com/reference/cmath/

C++ input value process as math function [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’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++

What does the modulus do? [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 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

Algorithm for solving simultaneous equations [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm making an mfc application in which I need to deduce if two lines intersect or not. For that I have the 2 equations:
x= [-x1y2 +x2y1 - (x2-x1)y ] / y1-y2
y= [-x3y4 +x4y3 - (y3-y4)x ] / x4-x3
But I need a way to solve these 2 equations simultaneously, How would I do that?
OK, assuming that x1,x2,x3,x4,y1,y2,y3,y4 are constant inside the process we can also write this as
x=a-b*y
y=c-d*x
with a=(-x1y2+x2y1)/y1-y2 etc.
Now substituting the first line into the second gives
y=c-d*(a-b*y)
y(1+d*b)=c-d*a
y=(c-d*a)/(1+d*b)
resubstituting into x=a-b*y gives the x part of the result