LakshyaEducation.in

VEDIC MATHS Video Series
  • Home
  • Video Series
    • Vedic Maths Videos
    • Quantitative Aptitude Videos
    • Class 8 Maths Videos
    • Class 9 Maths Videos
    • Class 10 Maths Videos
  • Quiz & Solutions
  • Blog
  • Store
  • Login
  • Contact Us
  • Home
  • Topic
  • C Programming
  • Floating Point Issues

C Programming

FLOATING POINT ISSUES MCQs

Total Questions : 28

Page 1 of 3 pages
Question 1.


What will be the output of the program?



#include<stdio.h>
int main()
{
float d=2.25;
printf("%e,", d);
printf("%f,", d);
printf("%g,", d);
printf("%lf", d);
return 0;
}

  1.    2.2, 2.50, 2.50, 2.5
  2.    2.2e, 2.25f, 2.00, 2.25
  3.    2.250000e+000, 2.250000, 2.25, 2.250000
  4.    Error
 Discuss Question
Answer is Option C. -> 2.250000e+000, 2.250000, 2.25, 2.250000

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.

Question 2.


What will be the output of the program?



#include<stdio.h>
#include<math.h>
int main()
{
float n=1.54;
printf("%f, %f\n", ceil(n), floor(n));
return 0;
}


  1.    2.000000, 1.000000
  2.    1.500000, 1.500000
  3.    1.550000, 2.000000
  4.    1.000000, 2.000000
 Discuss Question
Answer is Option A. -> 2.000000, 1.000000

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.

Question 3.


What will be the output of the program?



#include<stdio.h>
int main()
{
float a=0.7;
if(a < 0.7f)
printf("C\n");
else
printf("C++\n");
return 0;
}

  1.    C
  2.    C++
  3.    Compiler error
  4.    Non of above
 Discuss Question
Answer is Option B. -> C++

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

Question 4.


What will be the output of the program?



#include<stdio.h>
int main()
{
float f=43.20;
printf("%e, ", f);
printf("%f, ", f);
printf("%g", f);
return 0;
}

  1.    `4.320000e^(+01)`, 43.200001, 43.2
  2.    4.3, 43.22, 43.21
  3.    4.3e, 43.20f, 43.00
  4.    Error
 Discuss Question
Answer is Option A. -> `4.320000e^(+01)`, 43.200001, 43.2

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.

Question 5.


What will be the output of the program?



#include<stdio.h>
#include<math.h>
int main()
{
printf("%d, %d, %d\n", sizeof(3.14f), sizeof(3.14), sizeof(3.14l));
return 0;
}

  1.    4, 4, 4
  2.    4, 8, 8
  3.    4, 8, 10
  4.    4, 8, 12
 Discuss Question
Answer is Option C. -> 4, 8, 10

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.

Question 6.


What will be the output of the program?


#include<stdio.h>
#include<math.h>
int main()
{
printf("%f\n", sqrt(36.0));
return 0;
}

  1.    6.0
  2.    6
  3.    6.000000
  4.    Error: Prototype sqrt() not found.
 Discuss Question
Answer is Option C. -> 6.000000

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.

Question 7.


What will be the output of the program?



#include<stdio.h>
int main()
{
float *p;
printf("%d\n", sizeof(p));
return 0;
}

  1.    2 in 16bit compiler, 4 in 32bit compiler
  2.    4 in 16bit compiler, 2 in 32bit compiler
  3.    4 in 16bit compiler, 4 in 32bit compiler
  4.    2 in 16bit compiler, 2 in 32bit compiler
 Discuss Question
Answer is Option A. -> 2 in 16bit compiler, 4 in 32bit compiler

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.

Question 8.


What will be the output of the program?



#include<stdio.h>
int main()
{
float fval=7.29;
printf("%d\n", (int)fval);
return 0;
}

  1.    0
  2.    0.0
  3.    7.0
  4.    7
 Discuss Question
Answer is Option D. -> 7

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.

Question 9.


What will be the output of the program?



#include<stdio.h>
int main()
{
float a=0.7;
if(a < 0.7)
printf("C\n");
else
printf("C++\n");
return 0;
}

  1.    C
  2.    C++
  3.    Compiler error
  4.    Non of above
 Discuss Question
Answer is Option A. -> C

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

Question 10.

Which of the following statement obtains the remainder on dividing 5.5 by 1.3 ?


  1.    rem = (5.5 % 1.3)
  2.    rem = modf(5.5, 1.3)
  3.    rem = fmod(5.5, 1.3)
  4.    Error: we can't divide
 Discuss Question
Answer is Option C. -> rem = fmod(5.5, 1.3)

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

  • 1
  • 2
  • 3
  • Next →
  • Share on Facebook!
  • Share on Pinterest!

Sub Topics

  • Arrays
  • Bitwise Operators
  • C Preprocessor
  • Command Line Arguments
  • Complicated Declarations
  • Const
  • Control Instructions
  • Declarations And Initializations
  • Expressions
  • Floating Point Issues
  • Functions
  • Input / Output
  • Library Functions
  • Memory Allocation
  • Pointers
  • Strings
  • Structures
  • Subleties Of Typedef
  • Variable Number Of Arguments

Recent Posts

  • Ssc Exam Guide Book
  • Best Ssc Exam For Girls
  • Sail E0 Results 2022
  • Sail E0 Exam Results Cancelled - Exam Will Be Rescheduled
  • Vedic Maths Faq
  • Is Ssc Difficult Than Upsc?
  • Quantitative Aptitude Faqs

Recent Questions

Q.   The Value Engineering Technique In Which Experts Of The Same....

Q.   If Transcription Should Not Be Carried Out Beyond The Insert....

Q.   Buffalo Is To Leather As Llama Is To....?

Q.   Choose The Correct Answer From The Given Options To Fill The....

Q.   The Arithmetic Mean (average) Of The First 10 Whole Numbers ....

Q.   Which Governor General Is Remembered For The Annulment Of Th....

Q.   When The Voltage Across A Capacitor Is Tripled, The Stored C....

Q.   My Mother Bakes Cakes.

Q.   Log Mean Temperature Difference In Case Of Counter Flow Comp....

Q.   Which Of The Following Is Not A Matter Of Local Government?

Q.   Which Drugs Can Easily Pass The Placental Barrier?

Q.   Which Of The Following Is Not A Benefit Of BLAST?

Q.   A Part Of John's Salary Was Cut By The Government. What....

Q.   The Swollen Part Of The Pistil Is Known As ________ .

Q.   By Definition, Make A Map Is To Select Certain Features As R....

Q.   Which Of The Following Is The Best Tube Material From Therma....

Q.   If You Are Going To Use A Combination Of Three Or More AND A....

Q.   (a) A Ball Is Dropped From A Height Of 30m. After Striking T....

Q.   What Is The Approx. Value Of W, If W=(1.5)11, Given Log2 = 0....

Q.   In The Following Questions, The Symbols $, ©, *, @ And # Ar....

Topics

Computer Aptitude
SAIL Junior Officer (E-0)
10th Grade
11th Grade
12th Grade
4th Grade
5th Grade
6th Grade
7th Grade
8th Grade
9th Grade
NCERT
Cat
Commerce
Computer Science
Engineering
English
General Knowledge
Ias
Management
Quantitative Aptitude
Reasoning Aptitude
General Studies (Finance And Economics)
Vedic Maths
Analytical Instrumentation
Biochemistry
Bioinformatics
Biology
Biotechnology
Bitsat
Business Statistics
C Programming
C++ Programming
Cell Biology
Chemistry
Cost Accounting
Drug And Pharmaceutical Biotechnology
Electrical Measurement And Instrumentation
Environment Management
Environmental Biotechnology
Enzyme Technology
Financial Management And Financial Markets
Gate
General Science
Geography
Heat Transfer
History And National Movements
Human Anatomy And Physiology
Human And Cultural Diversity
Human Resource Management
Indian Economy
Indian Geography
Indian History
Indian Polity
Instrumentation Transducers
International Relations
Life Sciences
Marketing And Marketing Management
Mass Transfer
Mechanics Of Materials
Microbiology
Neet
Professional Communication
Renewable Energy
Sociology
Surveying
Total Quality Management
Uidai Aadhaar Supervisor Certification
Virology
LakshyaEducation.in
Lakshya Education
Bhilai,Chattisgarh,India
Email: admin@lakshyaeducation.in Phone: 07893519977 (WhatsApp)

Quick Links

  • Vedic Maths
  • Quantitative Aptitude
  • Class – IX Maths
  • Class – X Maths
  • Blog

Our Services

  • About us
  • Privacy
  • TOS
  • Refund / Cancellation
  • Contact
  • Affiliate Program
  • Copyright © 2022 All Right Reserved | Lakshya Education     ( )
    Login / Register

    Your Account will be created automatically when you click the below Google or Facebook Login Button.
    •   Login With Facebook
    •  Login With Google
     Login With Email/Password