Convert the binary number into base 2 scientific notation [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 17 days ago.
Improve this question
Sorry, maybe my explanation is not understandable (edit).
enter image description here
in the figure, to shorten the number, we use scientific notation, but shouldn't we use
a x 10^n
however in the image, using
a x 2^n
why use base 2.
isn't it if we add base 10 the right answer
this is the result if i use
a x 2^n
enter image description here
(it is not in accordance with)
this is the result if i use
a x 10^n
enter image description here
Thankyou for answer

In base 10, 1.010101001d x 10d^6 = 1010101.001d
In base 2, 1.010101001b x 10b^6 = 1010101.001b (but 10b = 2d)

Related

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.

Who can explain this code ? Why it shows 1 [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 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

Division Console output with a comma not rounded [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
Is there a way for the console output to be a decimal number with a comma my output is always rounded and i can barely us it like this.
Int a = 90 ;
Int b = 7;
Int c = a/b;
This out puts 13 not the actual value.
It is advice rewritten from my comment:
Please check any elementary C++ tutorial :) For your information there isn't bult-in type Int in C++, so it seems that you want to ask about int type division. The answer could be: store your result in some floating point type as float :)
You're welcome!
use float or double instead. int will never provide you with decimals.
Example:
float a=90,b=7;
float c = a/b;
printf("%.2lf",c);
The code avobe mentioned will write 2 decimals. If you want more, just change the 2 here %.2lf for your amount of decimals required.

How to calculate modulus? [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 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)

A computing trick to calculate for e.g number of boxes required to place N objects given each box can hold M objects? [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 9 years ago.
Improve this question
As a part of a recent topcoder SRM problem we had to compute number of buses "B" required to carry "N" people given that each bus has "S" seats.
What is the smartest way to compute this in C++?
The obvious way is to do:
if(N%S==0){B=N/S;}
else{ B=N/S + 1;}
^ ALL VARIABLES ARE INTEGERS, N AND S ASSIGNED APPROPRIATE VALUES
However I cant understand the logic behind the following code which is one particular topcoder user's solution which I was checking out;
B = (N + (S-1))/S;
How does this work?
The code
B = (N + (S-1))/S;
is a common rounding trick. We know that in integer division, the remainder is cut-off, essentially what floor does. In this case, we enforce a ceil operation by adding S-1 first.
This is similiar to the common way of rounding floating point numbers:
n = floor(n + 0.5);