C Programming Questions and Answers – Mathematical Functions
C Programming Questions and Answers – Mathematical Functions
1.What is the output of this C code?
#include <stdio.h>
#include <math.h>
int main()
{
int i = 90;
printf(“%f\n”, sin(i));
return 0;
}
a) Compile time error
b) Undefined behaviour
c) 0.893997
d) 1.000000
View Answer
Answer:a
2.What is the output of this C code?
#include <stdio.h>
#include <math.h>
int main()
{
unsigned int i = -1;
printf(“%f\n”, fabs(i));
return 0;
}
a) Compile time error
b) 1
c) -1
d) None of the mentioned
View Answer
Answer:d
3.function fabs defined math.h header file takes argument of type integer.
a) true
b) false
c) Depends on the implementation
d) Depends on the standard
View Answer
Answer:b
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
5.What is the output of this C code?
#include <stdio.h>
#include <math.h>
int main()
{
int i = 10;
printf(“%f\n”, log10(i));
return 0;
}
a) Compile time error
b) 1.000000
c) 2.302585
d) None of the mentioned
View Answer
Answer:b
6.What type of inputs are accepted by mathematical functions?
a) short
b) int
c) float
d) double
View Answer
Answer:d
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
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
9.Which of the following mathematical function requires 2 parameter for successful function call?
a) fmod();
b) div();
c) atan2();
d) All of the mentioned.
View Answer
Answer:d
10.Which mathematical function among the following does NOT require int parameters?
a) div(x, y);
b) srand(x);
c) sqrt(x);
d) All of the mentioned.
View Answer
Answer:c
11.sin(x) returns
a) sine of x where x is in radians
b) sine of x where x is in degree
c) cosine of x where x is in radians
d) cosine of x where x is in degree
View Answer
Answer:a
12.cos(x) returns
a) sine of x where x is in radians
b) sine of x where x is in degree
c) cosine of x where x is in radians
d) cosine of x where x is in degree
View Answer
Answer:c
13.What is the output of this C code?
#include <stdio.h>
#include <math.h>
void main()
{
int k = pow(2, 3);
printf(“%d\n”, k);
}
a) 9
b) 8
c) -1
d) 6
View Answer
Answer:b
14.What is the output of this C code?
#include <stdio.h>
#include <math.h>
void main()
{
int k = fabs(-87);
printf(“%d\n”, k);
}
a) -87
b) 87
c) 78
d) error
View Answer
Answer:b
15.What is the output of this C code?
#include <stdio.h>
#include <math.h>
void main()
{
int k = sqrt(-4);
printf(“%d\n”, k);
}
a) -2
b) 2
c) Compile time error
d) NaN
View Answer
Answer:d
16.Which among the following mathematical function do not have a “double” return-type?
a) srand(x);
b) ceil(x);
c) floor(x);
d) Both (b) and (c);
View Answer
Answer:a