C Questions and Answers – Mathematical Functions – 3

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Mathematical Functions – 3”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

1. Which of the following statement is correct?

    double x, y, z;
    x = 5.123456;
    z= modf(x, *y);

a) y stores integer part of x, z returns fractional part of x
b) y stores integer part of x, z returns integer part of x
c) y stores fractional part of x, z returns integer part of x
d) y stores fractional part of x, z returns fractional part of x
View Answer

Answer: a
Explanation: double modf(double x, double *y)
This function returns the fractional part of x, with the same sign. modf() function breaks the argument value into integer and fraction parts, each of which has the same sign as the argument. It stores the integer part as a double in the object pointed to by y.
advertisement
advertisement

2. A domain error occurs if x is negative and y is not an integral value for the function pow(double x, double y).
a) true
b) false
View Answer

Answer: a
Explanation: The pow() function computes x raised to the power y. A domain error occurs if x is negative and y is not an integral value. A domain error occurs if the result cannot be represented when x is zero and y is less than or equal to zero. A range error may occur.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

3. A function is declared as sqrt(-x) under the header file math.h, what will the function return?
a) square root of x
b) complex number
c) domain error
d) range error
View Answer

Answer: c
Explanation: double sqrt (double x);
The sqrt function computes the nonnegative square root of x. A domain error occurs if the argument is negative.

4. What will be the output of the following C code?

advertisement
    double x=1.2
    printf("%.1lf", ceil(x));

a) 1
b) 2
c) 1.0
d) 2.0
View Answer

Answer: d
Explanation: The ceil function returns the smallest integral value not less than x, expressed as a double.
advertisement

5. What will be the output of the following C code?

    double x=3,y= - 6;
    printf("%lf %lf", fabs(x), fabs(y));

a) 3 6
b) -3 6
c) 3.0 6.0
d) 3.000000 6.000000
View Answer

Answer: d
Explanation: double fabs(double x);
The fabs function computes the absolute value of a floating-point number X.

6. What will be the output of the following C code?

double x=1.8;
printf("%.2lf",floor(x));

a) 2.0
b) 2.00
c) 1.0
d) 1.00
View Answer

Answer: d
Explanation: double floor(double x);
The floor function computes the largest integral value not greater than x.

7. double ______ (double x, double y) computes the floating-point remainder of x/y.
a) modf
b) fmod
c) ceil
d) floor
View Answer

Answer: b
Explanation: double fmod(doublr x, double y);
The fmod() function computes the floating-point remainder of x/y.

8. sqrt(x) function is not faster than the apparent equivalent pow(x,0.5).
a) true
b) false
View Answer

Answer: b
Explanation: sqrt(x) function is generally much faster than the apparent equivalent pow (x, 0.5).

9. Which of the given C function can be used instead of the apparent identity pointed to by y?

int x=1; 
double y= 0.5 * (exp (x) + exp (-x));

a) cos(x)
b) cosh(x)
c) fmod(x)
d) modf(x)
View Answer

Answer: b
Explanation: The cosh function returns the hyperbolic cosine value. cosh(x)= 0.5 * (exp (x) + exp (-x))

10. Which function is used to recombine the fraction and exponent parts of a floating-point value after you have worked on them separately?
a) frexp()
b) exp()
c) modf()
d) Idexp()
View Answer

Answer: d
Explanation: ldexp() – Use this function to recombine the fraction and exponent parts of a floating-point value after you have worked on them separately.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.