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 11 of 15.

Trupti Patil said:   1 decade ago
Function written inside block is called local function & used only within that block. Function declared before main program starts below the header files is called global function.

Scope of local function is only within that part of the program it can not be access in other function.

Rajashekhar said:   1 decade ago
int main()? What's the function it is?

Shalivahana said:   1 decade ago
fmod() function or keyword is find used to find out.

Gayathridhiravidamani said:   1 decade ago
#include<stdio.h>
main()
{
float a=3.14,b=2.1,c;
c=a%b;
pf("%d",c);
output: invalid operand to binary%
BUT
int a;
a=3.14%2.1;
pf("%d",a);

Output 1:

I think so, comma act as a operator. Please clear explanation.

Rey said:   10 years ago
What is REM?

And I also need some information about what is the difference between.

Rem = 3.14% 2.1; and rem = fmod (3.14, 2.1);

Amer patel said:   10 years ago
If you use % for fining remainder it will give you an integer value.

But the fmmod() function gives you remainder in floating point value.

Madhuri said:   10 years ago
Nice explanation but I am not clear about increment.

Kalpanadevi said:   10 years ago
What is the maximum numbers of parameters that can be passed in printf and scanf?

Deepika said:   10 years ago
What is difference between fmod and modf?

Vela said:   10 years ago
Given explain is well.


Post your comments here:

Your comments will be displayed after verification.