Question: Question: Write a C program to input a line of characters in the form of a floatingpoint number, convert the line of characters into an

Question: Write a C program to input a line of characters in the form of a floatingpoint number, convert the line of characters into an actual floatingpoint number, and display on the standard output the floatingpoint number.

Implementation

The program is named lab4b . c. Use the given template lab4b.c ( BELOW ) and fill in your code.

You are given an array of characters of size MAX_SIZE where MAX_SIZE = 100. The array is

named my_strg.

Use getchar and a loop to read a line of characters, and store the input characters into array

my_strg. The loop terminates when a new line character ' is entered. The new line character ' is NOT part of the line (i.e., discard the new line character ' ).

The input line contains only characters '0 to '9 and the dot character '. in the form of a valid

positive floating point number of the following format: [integer part] . [fractional part]

Convert the input line of characters to a double floatingpoint number, which is stored in variable

my_number.

Display on the standard output the double floating-point number my_number using the printf statement as follows:

printf( "%.2f ", my_number );

Assume that the input line of characters represents a valid floating point number of the form [integer part] . [fractional part]

Sample Inputs/Outputs indigo 360 % lab4b 24.5

24.50

\

indigo 361 % lab4b 76.2421

76.24

\

indigo 362 % lab4b 100.0

100.00

\

indigo 363 o lab4b 0.255

0.26

indigo 364 % lab4b 12.9999999999 13.00

indigo 365 % lab4b 1.00000000099

1.00

indigo 366 % lab4b

----------------------------------------------------------------------------------------------------------------

#include  #define MAX_SIZE 100 main() { char my_strg[ MAX_SIZE ]; double my_number = 0.0; /********** Add your code below this line **********/ /********** Add your code above this line **********/ printf( "%.2f ", my_number ); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!