MCQs
printf("%e,", d); Here '%e' specifies the "Scientific Notation" format.
So, it prints the 2.25 as 2.250000e+000.
printf("%f,", d); Here '%f' specifies the "Decimal Floating Point" format.
So, it prints the 2.25 as 2.250000.
printf("%g,", d); Here '%g' "Use the shorter of %e or %f". So, it prints the
2.25 as 2.25.
printf("%lf,", d); Here '%lf' specifies the "Long Double" format. So, it prints
the 2.25 as 2.250000.
ceil(x) round up the given value. It finds the smallest integer not < x.
floor(x) round down the given value. It finds the smallest integer not > x.
printf("%f, %f`setminus`n", ceil(n), floor(n)); In this line ceil(1.54) round up the 1.54 to 2
and floor(1.54) round down the 1.54 to 1.
In the printf("%f, %f`setminus`n", ceil(n), floor(n)); statement, the format specifier "%f %f"
tells output to be float value. Hence it prints 2.000000 and 1.000000.
if(a < 0.7f) here a is a float variable and 0.7f is a float constant.
The float variable a is not less than 0.7f float constant. But both
are equal. Hence the if condition is failed and it goes to else it
prints 'C++'
Example:
#include<stdio.h>
int main()
{
float a=0.7;
printf("%.10f %.10fn",0.7f, a);
return 0;
}
Output:
0.6999999881 0.6999999881
printf("%e, ", f); Here '%e' specifies the "Scientific Notation" format. So,
it prints the 43.20 as 4.320000e+01.
printf("%f, ", f); Here '%f' specifies the "Decimal Floating Point" format. So,
it prints the 43.20 as 43.200001.
printf("%g, ", f); Here '%g' "Use the shorter of %e or %f". So, it prints the 43.
20 as 43.2.
sizeof(3.14f) here '3.14f' specifies the float data type. Hence size of float is 4 bytes.
sizeof(3.14) here '3.14' specifies the double data type. Hence size of float is 8 bytes.
sizeof(3.14l) here '3.14l' specifies the long double data type. Hence size of float is 10 bytes.
printf("%f`setminus`n", sqrt(36.0)); It prints the square root of 36 in the float format
(i.e 6.000000).
Declaration Syntax: double sqrt(double x) calculates and return the positive
square root of the given number.
sizeof(x) returns the size of x in bytes.
float *p is a pointer to a float.
In 16 bit compiler, the pointer size is always 2 bytes.
In 32 bit compiler, the pointer size is always 4 bytes.
printf("%d`setminus`n", (int)fval); It prints '7'. because, we typecast the (int)fval in to integer.
It converts the float value to the nearest integer value.
if(a < 0.7) here a is a float variable and 0.7 is a double constant.
The float variable a is less than double constant 0.7. Hence the if
condition is satisfied and it prints 'C'
#include<stdio.h>
int main()
{
float a=0.7;
printf("%.10f %.10f\n",0.7, a);
return 0;
}
Output:
0.7000000000 0.6999999881
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 5.5 by 1.3 is %lf\n", fmod (5.5, 1.3) );
return 0;
}
Output:
fmod of 5.5 by 1.3 is 0.300000