C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - General Questions (Q.No. 1)
1.
Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?
rem = 3.14 % 2.1;
rem = modf(3.14, 2.1);
rem = fmod(3.14, 2.1);
Remainder cannot be obtain in floating point division.
Answer: Option
Explanation:

fmod(x,y) - Calculates x modulo y, the remainder of x/y.
This function is the same as the modulus operator. But fmod() performs floating point divisions.

Example:


#include <stdio.h>
#include <math.h>

int main ()
{
  printf ("fmod of 3.14/2.1 is %lf\n", fmod (3.14,2.1) );
  return 0;
}

Output:
fmod of 3.14/2.1 is 1.040000

Discussion:
141 comments Page 7 of 15.

Manoj kumar said:   1 decade ago
External declaration means Declaring any variable before main() function or after main() function but not in main() function.

Example :

#include<stdio.h>

int S_no ;

main()
{
S_no=10;
printf ("%d\n",S_no);
}
Here I declared S_no Externally

Jagadeesh kumar said:   1 decade ago
It's nothing but difference between numerator and denominator.

Vinod kumar said:   1 decade ago
fmod(x,y) is floating point remainder of x/y,with the same sign as x.If y=0 ,the result is implementation-defined
e.g.

#include <stdio.h>
#include <math.h>

int main ()
{
printf ("fmod of 3.14/2.1 is %lf\n", fmod (3.14,2.1) );
return 0;
}
ans output:fmod of 3.14/2.1 is 1.040000

Pooja Papule said:   1 decade ago
But % operator also gives remainder in output.... So, we can also use %....

Manikandan said:   1 decade ago
What is the differnce b/w fmod and modf ?

Vishnu said:   1 decade ago
Please any one can help me how to execute program using gcc compiler ?

Vani said:   1 decade ago
#include<stdio.h>
main()
{
printf("%d",printf("ABC\"));
}

Can anyone please explain how it gives o/p as ABC4 ?

Siva Krishna said:   1 decade ago
@Vani :

In the inner printf statement, there are 4 characters.
The output of a printf stmt is a integer. that number is equal to the number of Characters that the printf statement printed.

For example:

printf("%d",printf("ABC"));
o/p= ABC4
-----------
printf("%d",printf("A"));
o/p= A1
-----------
printf("%d",printf("AB"));
o/p= AB2
-----------
printf("%d",printf("ABC10"));
o/p= ABC105
(here 10 is taken as two different characters.)
-----------

Elakkiah said:   1 decade ago
#include <stdio.h>
#include <math.h>

int main ()
{
float 3.13.2.1;
float R;
R=fmod(3.14,2.1);
printf ("The remainder is:",R);
scanf("%f",R);
return 0;
}

BDP said:   1 decade ago
% operator is not use for floating operations it is only used for integers.


Post your comments here:

Your comments will be displayed after verification.