C Programming Questions and Answers – Mathematical Functions – 1

«
»
This section on C questions and puzzles focuses on “Mathematical Functions”. One shall practice these questions and puzzles to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These programming puzzles can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C questions and puzzles on “Mathematical Functions” along with answers, explanations and/or solutions:

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

advertisement
  1.     #include <stdio.h>
  2.     #include <math.h>
  3.     int main()
  4.     {
  5.         int i = 90;
  6.         printf("%f\n", sin(i));
  7.         return 0;
  8.     }

a) Compile time error
b) Undefined behaviour
c) 0.893997
d) 1.000000
View Answer

Answer: c
Explanation: None.

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

advertisement
advertisement
  1.     #include <stdio.h>
  2.     #include <math.h>
  3.     int main()
  4.     {
  5.         unsigned int i = -1;
  6.         printf("%f\n", fabs(i));
  7.         return 0;
  8.     }

a) Compile time error
b) 1
c) -1
d) None of the mentioned
View Answer

Answer: d
Explanation: None.
advertisement

3. function fabs defined math.h header file takes the argument of type integer.
a) True
b) False
c) Depends on the implementation
d) Depends on the standard
View Answer

Answer: b
Explanation: None.
advertisement

4. log(x) function defined in math.h header file is __________
a) Natural base logarithm
b) Logarithm to the base 2
c) Logarithm to the base 10
d) None of the mentioned
View Answer

Answer: a
Explanation: None.

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

advertisement
  1.     #include <stdio.h>
  2.     #include <math.h>
  3.     int main()
  4.     {
  5.         int i = 10;
  6.         printf("%f\n", log10(i));
  7.         return 0;
  8.     }

a) Compile time error
b) 1.000000
c) 2.302585
d) None of the mentioned
View Answer

Answer: b
Explanation: None.

6. What type of inputs are accepted by mathematical functions?
a) short
b) int
c) float
d) double
View Answer

Answer: d
Explanation: None.

7. In linux, apart from including math header file, the program is successfully executed by which of the following?
a) cc filename.c
b) cc filename.c -lc
c) cc -math filename.c
d) cc -lm filename.c
View Answer

Answer: d
Explanation: None.

8. Which of the following is not a valid mathematical function?
a) frexp(x);
b) atan2(x,y);
c) srand(x);
d) fmod(x);
View Answer

Answer: d
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter