To print out a and b given below, which of the following printf() statement will you use?float a=3.14:double b=3.14;
Question
To print out a and b given below, which of the following printf() statement will you use?float a=3.14:double b=3.14;
Solution
To print out the float and double variables 'a' and 'b', you can use the printf() function in C programming language as follows:
printf("a = %.2f, b = %.2lf", a, b);
Here, %.2f is used to print the float variable 'a' up to 2 decimal places and %.2lf is used to print the double variable 'b' also up to 2 decimal places. The comma (,) is used to separate the two variables in the output.
Similar Questions
To scan a and b given below, which of the following scanf() statement will you use? #include<stdio.h> float a; double b;
What is the output of the following snippet code? float n = 123.1112F; printf("%.2f", n);A. 123.11B. 123.12C. 123.13D. 123.10
What will be the output of this code? #include <stdio.h> int main() { float f = 1.5e2; printf("%f", f); return 0; }Question 22AnswerA.1.500000B.15.000000C.150.000000D.150.0
What will be the output of the following C code? (Initial values: x= 7, y = 8)#include <stdio.h> void main() { float x; int y; printf("enter two numbers \n"); scanf("%f %f", &x, &y); printf("%f, %d", x, y); }
What will be the output of the following program?#include<stdio.h> int main() { int x = 3; float y = 3.0; if(x == y) printf("x and y are equal"); else printf("x and y are not equal"); return 0; }Select one:x and y are equalx and y are not equalErrorRandom output
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.