Find output of C programs (floating point)

Here, you will find, C programs with outputs and explanations based on floating point numbers their assignment, comparisons etc.
Submitted by Amit Shukla, on June 20, 2017

1) Select the correct floating point data type in C programming?

  1. float, double, int
  2. bool, double, long int
  3. long double, double, float
  4. long int, float


C) long double, double, float


In options A, B, C int, long int, bool functions present and these function store int values. Only in option C all the data types can contains floating point variables. You can also refer the following program:

The following program proofs that in C programming float and double datatype can contains float point variable and int data type cannot contains floating data type.

int main()
	float a;
	double b;
	int i;

	printf("Enter float value : ");
	printf("Float value : %f\n",a);

	printf("Enter double value : ");
	printf("Double value : %lf\n",b);

	printf("Enter int value : ");
	printf("Int value : %d\n",i);

	return 0;
Enter float value : 150.55
Float value : 150.550000
Enter double value : 150.55
Double value : 150.550000
Enter intvalue : 150.55
Intvalue : 150

2) How can we store 5.95 as a float?

  1. use 5.95f
  2. use 5.95
  3. use 5.95ld
  4. none of the above.


A) use 5.95f


In case of C and C++ programming 5.95 treat as double value by default. To convert double value into float value we have to use ‘f’ at the end of value. To specify 5.95 as long double we have to use character ‘L’ at the end of value.

3) Which of the following is range of float?

  1. -3.4E+37 to +3.4E+37
  2. -3.5E+37 to +3.5E+37
  3. -3.5E+38 to +3.5E+38
  4. -3.4E+38 to +3.4E+38


D) -3.4E+38 to +3.4E+38


The range of floating point primitive data type of size 32 bits is -3.4E+38 to +3.4E+38

4) How can we perform module operation (%) between two floating point variables 6.78 and 3.26?

  1. For floating point modulo is not define hence we cannot find modulo of floating variables.
  2. 6.78 % 3.26 is the result of modulus operation.
  3. int(6.78)%int(3.26) is the result of modulus operation.
  4. fmod(6.78,3.26) is the result of modulus operation.


D) fmod(6.78,3.26) is the result of modulus operation.


In C and C++ programming we cannot use modulus (%) operator directly to find modulus of any two floating point values or variables.

So there is a function fmod(floating point value 1, floating point value 2) using this function we can find the modulus of any two floating points variable. This function is available in header file <math.h>.

You can refer the following program for more detail:

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

int main()
	float a,b;
	printf("Enter 1st float value : ");
	printf("Enter 2nd float value : ");
	printf("Modulus of %f and %f is %f",a,b,fmod(a,b));
	return 0;
Enter 1st float value : 6.78
Enter 2nd float value : 3.26
Modulus of 6.780000 and 3.260000 is 0.260000

5) How can we round off any float variable f into a int value i?

  1. i=(int)(f+0.5)
  2. i=int(f+0.5)
  3. i=(int)x+0.5
  4. We cannot perform the given operation.


A) i=(int)(f+0.5)


In the given question we have to find out the round off value. It means replacing the floating number by nearest value that is approximately equal or smaller or greater to the given number.

You can refer the following program for more detail:


int main()
	float f;

	printf("Enter float value : ");

	int i = (int)(f + 0.5);
	printf ("Value after roundng off is %d\n",i);

	return 0;
Enter float value : 145.62
Value after roundng off is 146

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.