You are on page 1of 2

CSE1001 PROGRAMMING I

2022 – 2023 FALL


C PROGRAMMING EXERCISE - 02

Topic : Formatted Input/Output

Exercise-1 : What output do the following calls of the printf produce? (Use '*' to indicate one
space)

a) printf(“%6.2d, %-5.4d”, 86, 1040);


b) printf(“%-12.5e”, 30.253);
c) printf(“%7.4f”, 83.162);
d) printf(“%-8.4g”, .00000123);

Exercise-2 : Suppose that we call scanf as follows:

scanf(“%f%d%d”, &i, &x, &j);

If the user enters

.21 5.6 78

what will be the values of i, x, and j after the call? Assume that x and j are int variables and i is an
float variable.

Exercise-3 : Suppose that we call scanf as follows:

scanf(“%d%d%f”, &i, &x, &j);

If the user enters

21 5.6 78

what will be the values of i, x, and j after the call? Assume that x and i are int variables and j is an
float variable.

Exercise-4 : Write call of the printf that displays a float variable numf in the following format.

Exponential notation; left-justified in a field of size 6; 3 digit after the decimal point

Exercise-5 : Write call of the printf that displays a float variable numf in the following formats.

Fixed decimal notation; right-justified in a field of size 8; no digits after the decimal point.

Reference:K. N. King “C Programming: A Modern Approach”, Norton Publishing, 2nd Edition, 2008. 1 /2
Exercise-6 : Write call of the scanf that reads a floating-point number and stores in variable
number.

Exercise-7 : Write call of the scanf that reads a floating-point number and stores in variable
num1 and an integer store in variable num2.

Exercise-8 : Write call of the scanf that reads two integers in format 5-6 store in variable value1
and value2.

Exercise-9 : Suppose that two float variables num1 and num2 are 5.25 and 3.1 respectively.
Write call of the printf that displays

5.2500-3.1000=2.15

Exercise-10 : Suppose that two int variables num1 and num2 are 45 and 30 respectively. Write
call of the printf that displays

****45
****30
+_____
****75

'*' indicates one space.

Reference:K. N. King “C Programming: A Modern Approach”, Norton Publishing, 2nd Edition, 2008. 2 /2

You might also like