experiment 7: formatted...
TRANSCRIPT
Experiment 7: Formatted Input/Output(Part-I)
1.0. Objective and Scope
In this experiment important print formatting techniques in C programming language will be
examined.
1.1. Before the experiment
1.2. Implementation of the experiment
a) Write a printf statement for each of the following:
Print 1.234 in a 9-digit field width preceding zeros
Print 123.456789 in exponential notation with a sign (- or +) and 3-digits precision.
Print unsigned integer 40000 left justified in a 15-digit field with 8-digit.
b) Write what each of the following statements prints. If statement is incorrect indicate why.
printf( “%-10d\n”, 10000 );
printf( “%c\n”, “This is a string” );
printf( “%10.2E\n”, 444.93738 );
printf( “%10.2g\n”, 444.93738 );
printf( “%d\n”, 10.987 );
2
c) Write a program that converts integer Fahrenheit temperatures from 0 to 212 degrees to floating-
point Celsius temperatures with 3 digits of precision. Perform the calculation using the formula
celsius = 5.0 / 9.0 * ( fahrenheit - 32 );
Note: The output should be printed in two right-justified columns of 10 characters each, and the
Celsius temperatures should be preceded by a sign for both positive and negative values.
d) Write a program that uses the conversion specifier g to output the value 9876.12345. Print the value
with precisions ranging from 1 to 9.
1.3. Results
Write a report including what you have learned, your comments and answers of questions in the
experiment. (The report will be given to the one who is responsible of the experiment in the beginning
of the next lab.)