How do I make a basic c++ calculator calculate decimals [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 6 years ago.
Improve this question
I have a decent grasp with c++, and I made a basic calculator that can add, subtract, multiply, and divide. but I am having a hard time trying to get it to calculate decimals. Help please???

Read http://floating-point-gui.de/ first.
You don't calculate decimals, you display a floating point number (often some double) with some decimals.
Use things like std::showpoint & std::fixed ...
If you want to show a lot of correct digits, you need to do arbitrary precision arithmetic or BigNums. Then use a library, such as GMPlib

Related

Is there any optimal way to implement N byte integer and it's arithmetic operations in c++? [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 months ago.
Improve this question
I'm trying to think of some interesting, reusable way to implement big integers using passed amount of bytes or resizing themselves when needed. I have no idea how to make it optimal in any way tho. Are there any tricks I could use, or do I have to simply work on those numbers bit by bit while adding/multiplying/dividing?
edit: if it is important, I need it to safe text as number in base 10 so I can play with some ideas for encrypting it
Use The GNU Multiple Precision Arithmetic Library. If you try to reinvent the wheel you will end up with a square.

How do i take fifth power of a number in c [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 1 year ago.
Improve this question
I am creating a gp calculator in c++ ,But in gp the formulae has common ratio to the power of the term number. in order to get calculate that term i need to know how do i take the number as power for some other number, is there any operator for doing this.
If both arguments are floating point numbers, you have to use formula xᵐ = exp(m log x).
Supposedly std::pow does that for you. If your program requires to match some particular test patterns, further investigation may be required.
Know your <math>
As long as x != 0 to get any power:
exp(log(x)*power)
The interesting tidbit here is that if power is 1.0/y it will extract the y-root of the value.

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

increase long double accuracy [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 5 years ago.
Improve this question
how can I increase accuracy in double.
for example in this code:
#include <stdio.h>
int main() {
long double a = (long double) 5 / 3;
printf("%.62LLF", a);
return 0;
}
Floating Point Numbers have a limited precision. Mandatory Reading Here.
The boost.multiprecision library can give you access to higher precision floating point numbers, whether in the form of quad types which simply double the precision of double, or in the form of arbitrary precision rational numbers. If you're willing to take the time to learn how to install and use that library, you'll be able to improve the precision of your numbers.

What is the most efficient way to calculate PI in C? [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 5 years ago.
Improve this question
I'm have to write a C program, what it does is takes a integer as input. And gives output to the input(th) number of PI after decimal. Like if input is 100, output will be 9(100th digit of pi, after decimal is 9).
What will be the best algorithm for that?
p.s I don't want to save the value of pi into the string, and do it.
Your question is more a math question than a C programming one (so perhaps off-topic). Read first the wikipage on Pi and Approximations of π
If you need to compute only a few hundred (or even hundred thousands) digits, you just need to use some algorithm and code it using some bignum library (e.g. GMPlib, which has mpfr_const_pî ass commented by chtz).
Things become interesting for many billions of digits. I'm not expert on Pi, but look into Fabrice Bellard work on it (read the technical notes mentioning Chudnovsky's algorithm).