I made a simple C program to get a float as input from the user using scanf() function and dispay it using printf() function. But when the input number is quite large, the output deviates slightly. Why might that happen? For example: if I give input as 2345, out put will be as expected. But if I give the output as 1234567898, the output will be unexpected. #include &lt;stdio.h&gt;  int main() {     float number;     scanf(&quot;%f&quot;, &amp;number);     printf(&quot;The number %f&quot;, number);     return 0; }
27648
double r = 11.631; double theta = 21.4;   In the debugger, these are shown as 11.631000000000000 and 21.399999618530273.  How can I avoid this?
81025
How can I pad a string with spaces on the left when using printf?  For example, I want to print "Hello" with 40 spaces preceding it.  Also, the string I want to print consists of multiple lines.  Do I need to print each line separately?  EDIT: Just to be clear, I want exactly 40 spaces printed before every line.
96257
In C, are the shift operators (&lt;&lt;, &gt;&gt;) arithmetic or logical?
32798
I can print with printf as a hex or octal number.  Is there a format tag to print as binary, or arbitrary base? I am running gcc. printf(&quot;%d %x %o\n&quot;, 10, 10, 10); //prints &quot;10 A 12\n&quot; print(&quot;%b\n&quot;, 10); // prints &quot;%b\n&quot;
41750
If I type in a 16 digit number (format: number, no decimals) it changes the number on me. Example: 1234567812345678 changes the view to 1234567812345670.    If I type it in as a general format it changes the numbers above so it displays 1.23457E+15 but if you click on the cell, the display shows the last digit as a 0 instead of an 8 once again.   I opened the file on a different computer and same issue now with it.  I have changed the auto correction and auto formatting all to no avail.  Help!
66958
I want to do:  int a = 255;  cout &lt;&lt; a;   and have it show FF in the output, how would I do this?
25130
Of course most languages have library functions for this, but suppose I want to do it myself.  Suppose that the float is given like in a C or Java program (except for the 'f' or 'd' suffix), for example "4.2e1", ".42e2" or simply "42". In general, we have the "integer part" before the decimal point, the "fractional part" after the decimal point, and the "exponent". All three are integers.  It is easy to find and process the individual digits, but how do you compose them into a value of type float or double without losing precision?  I'm thinking of multiplying the integer part with 10^n, where n is the number of digits in the fractional part, and then adding the fractional part to the integer part and subtracting n from the exponent. This effectively turns 4.2e1 into 42e0, for example. Then I could use the pow function to compute 10^exponent and multiply the result with the new integer part. The question is, does this method guarantee maximum precision throughout?  Any thoughts on this?
91467
Is there a way to convert a character to an integer in C?   For example, from '5' to 5?
71603
This is a bc output, e.g.:  Input:  echo "scale=10; BLA-BLA-HERE-NOT-IMPORTANT" | bc   Output:   .3708446283953709207058828124021300754352578903651372655882743141882\ 77124645102027246581819139527644919407424570060822470537797066353573\ 96635.8038454068 days   Two Questions:   can the output be rounded to something like "0.3708..."? can I remove the "\n"-s from the end?   I can't find any max width option in bc.
60259
What is the difference between decimal, float and double in .NET?  When would someone use one of these?
95859
Why does C/C++ differentiates in case of array index out of bound #include &lt;stdio.h&gt; int main() {     int a[10];     a[3]=4;     a[11]=3;//does not give segmentation fault     a[25]=4;//does not give segmentation fault     a[20000]=3; //gives segmentation fault     return 0; }  I understand that it's trying to access memory allocated to process or thread in case of a[11] or a[25] and it's going out of stack bounds in case of a[20000]. Why doesn't compiler or linker give an error, aren't they aware of the array size? If not then how does sizeof(a) work correctly?
67106
Is there a function to round a float in C or do I need to write my own?       float conver = 45.592346543;   I would like to round the actual value to one decimal place, conver = 45.6.
2846
Why does the following behave unexpectedly in Python?  &gt;&gt;&gt; a = 256 &gt;&gt;&gt; b = 256 &gt;&gt;&gt; a is b True           # This is an expected result &gt;&gt;&gt; a = 257 &gt;&gt;&gt; b = 257 &gt;&gt;&gt; a is b False          # What happened here? Why is this False? &gt;&gt;&gt; 257 is 257 True           # Yet the literal numbers compare properly   I am using Python 2.5.2. Trying some different versions of Python, it appears that Python 2.3.3 shows the above behaviour between 99 and 100.  Based on the above, I can hypothesize that Python is internally implemented such that "small" integers are stored in a different way than larger integers and the is operator can tell the difference. Why the leaky abstraction? What is a better way of comparing two arbitrary objects to see whether they are the same when I don't know in advance whether they are numbers or not?
24750
I've just encountered a weird problem, I'm trying to printf an integer variable, but I forgot to specify the variable name, i.e.  printf("%d");   instead of  printf("%d", integerName);   Surprisingly the program compiles, there is output and it is not random. In fact, it happens to be the very integer I wanted to print in the first place, which happens to be m-1.  The errorneous printf statement will consistently output m-1 for as long as the program keeps running... In other words, it's behaving exactly as if the statement reads  printf("%d", m-1);   Anybody knows the reason behind this behaviour? I'm using g++ without any command line options.  #include &lt;iostream&gt; #define maxN 100 #define ON 1 #define OFF 0  using namespace std;  void clearArray(int* array, int n); int fillArray(int* array, int m, int n);  int main() {     int n = -1, i, m;     int array[maxN];     int found;      scanf("%d", &amp;n);      while(n!=0)     {         found=0;         m = 1;         while(found!=1)         {             if(m != 2 &amp;&amp; m != 3 &amp;&amp; m != 4 &amp;&amp; m != 6 &amp;&amp; m != 12)             {                 clearArray(array, n);                 if(fillArray(array, m, n) == 0)                 {                     found = 1;                 }             }             m++;         }          printf("%d\n");          scanf("%d", &amp;n);     }      return 0; }  void clearArray(int* array, int n) {     for(int i = 1; i &lt;= n; i++)         array[i] = ON; }  int fillArray(int* array, int m, int n) {     int i = 1, j, offCounter = 0, incrementCounter;      while(offCounter != n)     {         if(*(array+i)==ON)          {             *(array+i) = OFF;             offCounter++;                }         else          {             j = 0;             while((*array+i+j)==OFF)             {                 j++;             }             *(array+i+j) = OFF;             offCounter++;                    }         if(*(array+13) == OFF &amp;&amp; offCounter != n) return 1;         if(offCounter ==n) break;          incrementCounter = 0;                while(incrementCounter != m)         {             i++;             if(i &gt; n) i = 1;             if(*(array+i) == ON) incrementCounter++;          }            }      return 0; }
115153
I know you can't rely on equality between double or decimal type values normally, but I'm wondering if 0 is a special case.  While I can understand imprecisions between 0.00000000000001 and 0.00000000000002, 0 itself seems pretty hard to mess up since it's just nothing.  If you're imprecise on nothing, it's not nothing anymore.  But I don't know much about this topic so it's not for me to say.  double x = 0.0; return (x == 0.0) ? true : false;   Will that always return true?
17181
echo "scale=3;1/8" | bc   shows .125 on the screen. How to show 0.125 if the output result is less than one?
44888
I'm reading The C++ Programming Language and in it Stroustrup states that the int value of a char can range from 0 to 255 or -127 to 127, depending on implementation. Is this correct? It seems like it should be from -128 to 127.  If not, why are their only 255 possible values in the second implementation possibility, not 256.