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

Gautam said:   1 decade ago
Please explain fmod() and modf ().

POOJA said:   1 decade ago
Difference between fmode(), modef() and mode()?

Shubham choudhary said:   1 decade ago
Why did ansi form fmod() operator when % already was. It could be used for both the purpose. Integers as well as float?

Shakir Baba said:   1 decade ago
Why array's base address is initialized to 0 and it terminates on -1?

Janani said:   1 decade ago
What is the difference between an identifier and variable?

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

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

I am getting output as 0. Anyone can explain it why?

Shambhu kumar said:   1 decade ago
What is wrong in this code why it will give segmentation fault?

#include <stdio.h>
void main()
{
register int x = 0;
if (x < 2)
{
x++;
main();
}
}

Dhara said:   1 decade ago
What different between fmod & modf?

Sujitha said:   1 decade ago
@Ayapan.

You have declared the fun as fmod(3, 2).

When 3 gets divided by 2 it gives 1.5 with remainder 0.

Pooja said:   1 decade ago
@Vani.

printf inside the printf....firstly there is a abc and also a slace is a character literal so there it work as a character...and 1 char is 1 byte so 4 character print 4...on place of printf("%d",4 );

Due to %d it'll print 4.


Post your comments here:

Your comments will be displayed after verification.