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 ?
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 14 of 15.
Afsia said:
9 years ago
Difference between modf and fmod is fmod gives remainder when x divided y. Fmod stands for floating modulus while in modf the parts spilt in two modfvalue into an integer and a fractional part. The fraction is returned by the modf function and the integer part is stored in the iptr variable. Iptr means pointer to the variable stored in an integer.
Banu said:
9 years ago
What is the correct answer for this question?
Tanushi said:
8 years ago
Please explain how this work?
Nayan said:
8 years ago
What is the meaning of %lf ? Or why not use %f only?
Venkat said:
8 years ago
#include<stdio.h>
#include<math.h>
main()
{
float a=1.2,b=2.3,c;
c=a%b;
printf("%f\n",fmod(a,b));
}
~
Test1.c:6:4: error: invalid operands to binary % (have \'float\' and \'float\')
user@user:~/c/test$
I have tested in GCC it gives error so finally conclusion is % this operator not possible for floating points
#include<math.h>
main()
{
float a=1.2,b=2.3,c;
c=a%b;
printf("%f\n",fmod(a,b));
}
~
Test1.c:6:4: error: invalid operands to binary % (have \'float\' and \'float\')
user@user:~/c/test$
I have tested in GCC it gives error so finally conclusion is % this operator not possible for floating points
Shahi said:
8 years ago
What is the function %lf here?
Piyush said:
8 years ago
Why option A is incorrect?
S.sasindra said:
8 years ago
Option A is also correct becuase;
int rem=3.14/2.1;
printf("%d",rem);
return();
int rem=3.14/2.1;
printf("%d",rem);
return();
Prerna said:
8 years ago
fmod is not working in GCC compiler. How can I use this in GCC compiler?
Please suggest me to get the output of this.
Please suggest me to get the output of this.
Varadaraj said:
7 years ago
As per my knowledge, it is option A.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers