What would be the best way to remove the decimal point from a float number? For instance if I have a float number .2546 I would like to be able to remove the dot and use just the number (int) 2546 for some calculations.
Maybe, convert to string than remove the first character from the string than convert the string back to an int?
I was going through the exercises in one C programming ebook.There is this question which asks me to print a float variable in fixed decimal notation, field size of 6, right-justified, no digits after decimal point.I got printf("%6f", x );
x = float variable.
But the above code prints numbers after the decimal point, so I changed it to %d. But %d doesn't work with float variables..
How to return the value after the decimal point. For example:if two integer numbers are 3, 4 then (3+4)/2 is 3.5 the 5 after the decimal point is to be returned. if suppose it is 34.456 i have to return 456.
Question: A computer uses 10 bits to store integers with 1 bit for a sign. It stores an approximation of real numbers in 10 bits. The first bit of the first five is the sign of the mantissa and the other four bits are the mantissa. The first bit of the second five is the sign of the exponent and the other four the exponent.
1)What is the range of integers?
2)what is the range of real numbers(Float Type)
The first question was simple. I just found the smallest 10 digit binary number 1000000000 = -512 and then found the largest 10 digit binary number which would have to be 0111111111 = 511, therefore the range of integers is from -512 to 511.
For the second question - I am either making this harder than it is, or it really is a challenging question. So I followed the steps and first I was thinking I would take the number 1000000000 and convert this to a decimal (assuming its a 10 bit float)...But, can you even do this with a 10 bit float??
I ended up getting 1000000000 (after denormalizing) = .000100000 = 0.625.. would that be the minimum range? If so, then I know what I need to do to find the maximum , but if not - then I am really lost.
My Process was:
1.00000 X 2^(-4) = my final result of 0.625 after converting.
I am trying to find out when using float in a calculation how to set the number of decimal places. For example my code below
Code: #include stdio.h> int main() { float x=123.0;
[Code]....
This returns an answer 8487.0000 I would like it not to show all the decimal places. However if the sum has decimal places I would like to select the number of decimal places shown.
I have a simple input output problem using float point numbers and after the first input the program skips the other cin functions is there something that I did wrong? It compiles fine also.
Code: #include <iostream> #include <float.h> using namespace std; int main() { int x; int y; int z;
Code: Complete the program below which converts a binary number into a decimal number. Sample outputs are shown belowComplete the program below which converts a binary number into a decimal number. Sample outputs are shown below.
Sample Output 1:
8-bit Binary Number => 11111111 Decimal Number = 255
Sample Output 2:
8-bit Binary Number => 10101010 Decimal Number = 170
Sample Output 3:
8-bit Binary Number => 101010102 Number entered is not a binary number
#include <iostream> using namespace std; int main() { int num;
I am entering numbers to float ... I want program to find out, which first number is not from specific interval. How to do it ? Example: Enter input : 5 10 20 30 50 46 . 30 is invalid. Here is the code :
Code:
while(scanf("%f",&input)!=EOF || input==0) { sum=input+sum; if (getchar() == '
I know how to remove digits in number from right to left.For example: the number 319. If I do (number /= 10), I get 31.how can I remove digits in number from left to right.For example: the number 319. If I will do something, I will get the number 19.
I am trying to remove the first digit so if the user enters 12345 it should output 2345 the code i have works only for removing the last digit how would i go about removing the first one?
#include <iostream> using namespace std; int removeFirst(int n); int main(){ int n, m; cout << "enter number" << endl;
How do you convert a number float in a range of -10.0f to 17.0f to a eqivalent number in the range of 0.0f to 1.0f?The code does not work well. floaty is the float to change.
//change range to 0..1 diamond[x][y] = (floaty - minY) / (maxY - minY);
I am very new to programming and have been working on a program that can receive decimals or binary numbers and convert them. The decimal --> binary works fine. For some reason I cannot figure out I cannot get the "BinaryToDecimal" function to perform. By putting a "printf" into the for-loop.
Code:
#include <stdio.h>#include <string.h> #include <math.h> char* ReverseString (char _result[]) { int start, end, length = strlen(_result); char swap; for (start = 0, end = length-1; start < end; start++, end--)
I have a code and am asked to modify it so that it will take as input as unsigned binary number up to 16 digits in length and convert it into its equivalent decimal number and output that decimal number.
All I know is that I use library function strlen() in <cstring> to calculate the length of the input string.
I also know I have to use something called pow(2,4);
//pow (); is found in cmath
I was told to use sum = sum >>16-l; (l is the length of />/>
#include <iostream> using namespace std; int main() {
I am unable to find why my code is going into infinite loop as below. This works perfectly fine if I keep entering just the integer values but if I enter a float number it ends up in an infinite loop
int main() { int x; while(1){ cin>>x; cout <<x; } return 0; }
I'm writting an algorithm which equals to std::to_string. The inttostring part is fine, and the decimal_part too. But when the number digits > 5, the program loops infinitely.
#include "stdio.h" #include <stdarg.h> #include <math.h> // Main Function int main(void){ int number; printf(" Please enter a number from 1-10? "); scanf("%d", &number);
[Code] ....
I took the while statement out didn't want that in there.