Monday 15 April 2013

c - Why we can't use operator % for float and double type operands? -


I'm new to C / C ++, so I have some questions about a basic type:

  1. I have read somewhere that the operator can not be applied to float or operands of two types. So how can I see the difference of float or double variables? I have shown my program with the error below:

      #include & lt; Stdio.h & gt; Int main () {double en, k, t, ii; Int j = 0; Scanf ("% f% f", & amp; n, & amp; amp; amp; amp; amp; amp; amp; amp;; I = 0; While (i & lt; n) {scanf ("% f", & amp; t); If (t% k == 0) / * error: binary% * / j ++; I ++; } Printf ("% d", j); Return 0; If there is a positive integer limit of 10 ^ 9, then which qualifier should I use or how to get such a large range?       

    here fmod There is an option for the answer - Answer the question originally asked (Since you were using the double type. If your comments are clear, you can actually Just want to use the integer type, you can type your code as follows ( unsigned long integer type to give you many headroom A):

      #include  int main () {unsigned long integer n, k, ("% llu", & amp; n); Printf ("Enter the Factor:"); Scan F ("% llu", "i, j = 0"; printf ("Enter the number of attempts"); & amp; amp; k); i = 0; (I & lt; n) {printf ("\ n Enter the number to test:"); scanf ("% llu", & amp; t); if (t% k == 0) J ++; I ++;} printf ("Number of deposits% llu \ n", j); return 0;}   

    Note I have tried I / O slightly more descriptive - the user signals A good idea to give Rather than waiting for him instead of a blinking cursor. Obviously I'm guessing some estimates (maybe not the language you want to use ...)

No comments:

Post a Comment