LearnFrenzy
Sign in Take a free test

C Library Functions · Predict the Output · Question 1

pow, sqrt, fabs and ceil/floor on negatives Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

What is the output of the following C program?

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

int main(void) {
    printf("%.0f %.0f %.1f\n", pow(3, 4), sqrt(169), fabs(-0.5));
    printf("%.1f %.1f\n", ceil(-2.5), floor(-2.5));
    return 0;
}
  • A 81 13 0.5 -2.0 -3.0 Correct
  • B 81 13 0.5 -3.0 -2.0
  • C 12 13 0.5 -2.0 -3.0
  • D 81 13 -0.5 -2.0 -3.0
Correct Answer: Option A

ceil rounds toward +∞ (−2.0) and floor toward −∞ (−3.0), also for negative numbers.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links